XML 文件的预览渲染期间抛出异常 16,并且一个字符串抛出错误 "is translated here but not in default locale"
Exception 16 is thrown during Preview Rendering of XML file and one string throws error "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(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 is translated here but not in default locale"。问题是,错误消息显示在默认的 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 文件中更改为所需的值,渲染工作没有问题。不过我不知道为什么这会影响渲染。
我有以下 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(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 is translated here but not in default locale"。问题是,错误消息显示在默认的 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 文件中更改为所需的值,渲染工作没有问题。不过我不知道为什么这会影响渲染。