0

当我在我的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 但它似乎是正确的。我的values-it目录下的question_menu.xml:

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

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

4

1 回答 1

1

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

始终在默认目录中保留每个资源的副本,不带后缀(例如,res/values/)。然后,根据需要覆盖这些资源(例如,翻译到不同的res/values-XXX/目录)。这样,每个配置总是有可用的资源。

于 2013-11-01T16:53:11.540 回答