AVD错误:无法启动活动ComponentInfo {...}:android.view.InflateException:二进制XML文件:错误膨胀类android.widget.Spinner

时间:2013-11-01 16:30:58

标签: java android xml avd

当我在galaxy nexus(Android 4.2.1)上运行程序时,一切正常。但是当我在模拟器上尝试它时(我试过3.0和4.3)我得到了这个错误。

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>

它看起来像是由微调器的条目生成的错误:@ array / subjectName但似乎是正确的。 我的question_menu.xml目录下的值为:it:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string-array name="subjectName">
        <item>Stuff</item>
    </string-array>
</resources>

我是否需要在目录值下没有本地化的另一个question_menu.xml?

1 个答案:

答案 0 :(得分:1)

如果您的模拟器未设置为意大利语语言环境,并且某个地方subjectName中没有res/values/资源,则会崩溃。我本来期望一个稍微不同的异常(ResourceNotFoundException),但我没有尝试使用字符串数组资源。

始终拥有默认目录中每个资源的副本,没有后缀(例如res/values/)。然后,根据需要覆盖这些资源(例如,转换到不同的res/values-XXX/目录)。这样,每个配置始终都有可用的资源。