Issue
All works fine when I run the program on my galaxy nexus (Android 4.2.1). But when I try it on the emulator (I tried 3.0 and 4.3) I get this error.
FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.noware.testconcorsi.easytest/com.noware.testconcorsi.selection.MainActivity}: android.view.InflateException: Binary XML file line #27: Error inflating class android.widget.Spinner
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #27: Error inflating class android.widget.Spinner
at android.view.LayoutInflater.createView(LayoutInflater.java:620)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at com.noware.testconcorsi.selection.MainFragment.onCreateView(MainFragment.java:40)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:870)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1080)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:622)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1416)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:505)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1171)
at android.app.Activity.performStart(Activity.java:5143)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
... 11 more
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at android.view.LayoutInflater.createView(LayoutInflater.java:594)
... 27 more
Caused by: java.lang.NullPointerException
at android.content.res.AssetManager.getResourceTextArray(AssetManager.java:215)
at android.content.res.Resources.getTextArray(Resources.java:443)
at android.content.res.TypedArray.getTextArray(TypedArray.java:628)
at android.widget.AbsSpinner.<init>(AbsSpinner.java:74)
at android.widget.Spinner.<init>(Spinner.java:160)
at android.widget.Spinner.<init>(Spinner.java:139)
at android.widget.Spinner.<init>(Spinner.java:123)
... 30 more
Here the xml that I inflate:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/mainFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/backgroundColor" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/titleCompleteSimulation"
style="@style/textTitleStyle"
android:text="@string/titleCompleteSimulation" />
<ListView
android:id="@+id/listAll"
style="@style/listGrayStyle" />
<TextView
android:id="@+id/titleSubjectSimulation"
style="@style/textTitleStyle"
android:text="@string/titleSubjectSimulation" />
<Spinner
android:id="@+id/subject_spinner"
android:layout_width="0dp"
android:layout_height="0dp"
android:entries="@array/subjectName"
android:orientation="horizontal"
android:spinnerMode="dialog"
android:textColor="#040404"
android:textSize="@dimen/titleRowTextSize" />
<Button
android:id="@+id/spinnerFakeButton"
android:layout_width="fill_parent"
android:layout_height="60dp"
android:background="@drawable/list_selector"
android:divider="#b5b5b5"
android:dividerHeight="1dp"
android:drawableRight="@drawable/arrow_down"
android:gravity="left|center_vertical"
android:padding="15dp"
android:text="@string/dummy"
android:textColor="#040404"
android:textSize="@dimen/titleRowTextSize"
android:textStyle="bold|italic"
android:typeface="sans" />
<ListView
android:id="@+id/listSubject"
style="@style/listGrayStyle" >
</ListView>
</LinearLayout>
It looks like an error generated from the spinner's entries: @array/subjectName But It seems correct. My question_menu.xml under the directory values-it:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="subjectName">
<item>Stuff</item>
</string-array>
</resources>
Do I need another question_menu.xml not localizated under the directory values?
Solution
If your emulators are not set up for Italian locale, and you do not have a subjectName
resource in res/values/
somewhere, you will crash. I would have expected a slightly different exception (ResourceNotFoundException
), but I have not tried this scenario with string array resources.
Always have a copy of every resource in a default directory, with no suffixes (e.g., res/values/
). Then, override those resources as needed (e.g., translations into different res/values-XXX/
directories). That way, there is always a resource available for every configuration.
Answered By - CommonsWare
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.