Исключение 16 выдается во время предварительного просмотра XML-файла, и одна строка выдает ошибку «переводится здесь, но не в локали по умолчанию» - PullRequest
0 голосов
/ 28 ноября 2018

У меня есть следующий XML-файл:

        <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        tools:context="com.ad123.oshikwanyamadictionary.EditorActivity"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:padding="7dp"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            tools:text="term in question"
            android:textSize="20sp"
            android:paddingTop="3dp"
            android:paddingStart="3dp"
            android:paddingLeft="3dp"
            android:paddingBottom="10dp"
            android:gravity="center_horizontal"
            android:id="@+id/term_in_question"/>
        <AutoCompleteTextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="textCapSentences"
            android:hint="@string/translation_suggestion"
            android:id="@+id/suggestion_edit_text"
            />
        <Spinner
            android:paddingTop="10dp"
            android:paddingLeft="3dp"
            android:paddingStart="3dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"

            android:id="@+id/language_report_spinner">
        </Spinner>
        <!--android:entries="@array/sourceLanguage"
            android:entries="@array/wordType"-->
        <Spinner
            android:paddingTop="15dp"
            android:paddingLeft="3dp"
            android:paddingStart="3dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/word_type_spinner"
            android:visibility="gone">
        </Spinner>
        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:inputType="textCapSentences"
            android:id="@+id/term_plural_edit_text"
            android:hint="@string/plural_of_term_contribution"
            android:visibility="gone"/>
        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:inputType="textCapSentences"
            android:visibility="gone"
            android:id="@+id/translation_plural_edit_text"
            android:hint="@string/plural_of_translation_contribution"/>
        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:visibility="gone"
            android:id="@+id/term_example_edit_text"
            android:hint="@string/example_using_term_contribution"/>
        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:inputType="textCapSentences"
            android:visibility="gone"
            android:id="@+id/translation_example_edit_text"
            android:hint="@string/example_using_translation_contrinution"/>
        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:inputType="textCapSentences"
            android:visibility="gone"
            android:id="@+id/alternative"
            android:hint="@string/alternative_edit_text"/>
        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:id="@+id/send_data"
            android:text="@string/send_data"
            android:backgroundTint="@color/Button"/>
        <ProgressBar
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_gravity="center_horizontal"
            android:layout_margin="5dp"
            android:visibility="gone"
            android:id="@+id/progress_bar_edit"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/or_edit_choose"/>
</LinearLayout>

Теперь, если я пытаюсь его предварительно просмотреть, он выдает следующее исключение:

java.lang.ArrayIndexOutOfBoundsException: 16
    at android.text.StaticLayout.generate(StaticLayout.java:854)
    at android.text.StaticLayout.<init>(StaticLayout.java:603)
    at android.text.StaticLayout.<init>(StaticLayout.java:50)
    at android.text.StaticLayout$Builder.build(StaticLayout.java:425)
    at android.widget.TextView.makeNewLayout(TextView.java:8272)
    at android.widget.TextView.assumeLayout(TextView.java:8104)
    at android.widget.TextView.onPreDraw(TextView.java:6742)
    at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:977)
    at android.view.AttachInfo_Accessor.dispatchOnPreDraw(AttachInfo_Accessor.java:46)
    at com.android.layoutlib.bridge.impl.RenderSessionImpl.renderAndBuildResult(RenderSessionImpl.java:404)
    at com.android.layoutlib.bridge.impl.RenderSessionImpl.renderAndBuildResult(RenderSessionImpl.java:543)
    at com.android.layoutlib.bridge.impl.RenderSessionImpl.render(RenderSessionImpl.java:426)
    at com.android.layoutlib.bridge.BridgeRenderSession.render(BridgeRenderSession.java:108)
    at com.android.ide.common.rendering.api.RenderSession.render(RenderSession.java:154)
    at com.android.ide.common.rendering.api.RenderSession.render(RenderSession.java:136)
    at com.android.tools.idea.rendering.RenderTask.lambda$renderInner$5(RenderTask.java:671)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

Я уже пытался очистить проекта также изменить целевой API предварительного просмотра, но ничего не помогает.В то же время я получаю сообщение об ошибке только для одной строки.Это строка, использованная в последнем TextView: @ String / or_edit_choose.Хотя он переведен на все языки, он все равно выдает мне сообщение об ошибке: «or_edit_choose переводится здесь, но не в локали по умолчанию».Дело в том, что сообщение об ошибке отображается мне в файле strings.xml по умолчанию, который должен быть языковым стандартом по умолчанию.Я не знаю, связаны ли ошибки, но они оба обнаружились одновременно.Был также короткий момент, когда к строке можно было получить доступ из другого файла макета, но не из приведенного выше.Теперь к нему нельзя получить доступ ни из одного файла.

Ответы [ 2 ]

0 голосов
/ 28 ноября 2018

Видимо, тег android: visibility = "пошел" сделал рендеринг невозможным.После того, как я изменил его на видимый в xml, чтобы изменить его в java-файле на необходимые значения, рендеринг работал без проблем.Я понятия не имею, почему это может повлиять на рендеринг.

0 голосов
/ 28 ноября 2018

In strings.xml добавить эту строку

tools:ignore="ExtraTranslation" xmlns:tools="http://schemas.android.com/tools"

в <resources> тег

как этот

<resources tools:ignore="ExtraTranslation" xmlns:tools="http://schemas.android.com/tools">
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...