所有工作正常,當我在我的星系聯盟(Android 4.2 0.1)。但是當我在模擬器上嘗試它時(我試過3.0和4.3),我得到這個錯誤。AVD錯誤:無法啓動活動ComponentInfo {...}:android.view.InflateException:二進制XML文件:錯誤膨脹類android.widget.Spinner
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
這裏說我膨脹的xml:
<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>
它看起來像從旋轉的條目產生一個錯誤:@數組/主旨名稱,但它似乎是正確的。 我的目錄下的值,它question_menu.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="subjectName">
<item>Stuff</item>
</string-array>
</resources>
我需要下的目錄值不localizated另一個question_menu.xml?
謝謝,我想,我只是想象一下,如果唯一存在的資源只有一種語言,系統將使用它。 我沒有其他語言,所以我把所有的東西都移到/ res/values /它只是以這種方式看起來很混亂。最佳做法是什麼? – Accollativo
@Accollativo:「我把所有的東西都搬到了/ res/values /這只是這樣,看起來很亂」 - 我不知道爲什麼你會認爲這是「混亂」,因爲這是正確的答案。對於字符串,在'res/values /'中有**每個**字符串的副本,無論您希望如何考慮默認語言。 – CommonsWare
因爲在res/values /我有不需要翻譯的字符串 – Accollativo