在 XML 文件的预览呈现期间引发异常 16,一个字符串引发错误"is translated here but not in default locale"



我有以下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文件中,该文件应该是默认的语言环境。我不知道这些错误是否有关联,但它们同时出现。还有一个短暂的时刻,字符串可以从另一个布局文件访问,只是不能从上面给出的文件访问。现在无法从任何文件访问它。

strings.xml中添加此行

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

<resources>标签

像这个

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

显然,标签android:visibility="gone"导致无法进行渲染。在我将其更改为在xml中可见,并将其在java文件中更改为所需的值之后,渲染工作没有问题。但我不知道为什么这会影响渲染。

相关内容

最新更新