我转向字符串数组,这在arrays.xml中是不存在的

时间:2015-06-27 20:28:48

标签: android fragment translation

我是Android开发的新手,我正在尝试开发一个应用程序,但我遇到了崩溃。

这是我的strings.xml,其中还包含一些string-arrays - 当我尝试获取其中一个数组(见下文)时,我的应用程序崩溃了。

<string-array name="Insurance_type">
        <item>Comprehensive</item>
        <item>Required</item>
    </string-array>

       <string-array name="Private">
        <item>@string/Abarth</item>
        <item>@string/Audi</item>
     </string-array>

    <string-array name="Audi">
        <item>@string/A1</item>
        <item>@string/A3</item>
        <item>@string/New_A3</item>
        <item>@string/A4</item>
        <item>@string/A5</item>
        <item>@string/S1</item>
        <item>@string/Audi80</item>
    </string-array>

    <string-array name="A3">
        <item>TFSI(1197)Automat Attraction 105hp</item>
        <item>TFSI(1197)Automat Sharp 105hp</item>
        <item>TFSI(1390)Automat Limiter 3 Doors</item>
        <item>TFSI(1390)Automat Limiter 5 Doors</item>
        <item>TFSI(1390)Automat Sharp 3 Doors</item>
        <item>Automat(1595)3 Dors Attraction</item>
        <item>Automat(1781)3 Dors Ambiente</item>
        <item>Automat(1595)5 Dors New shape Attraction</item>
    </string-array>

    <string-array name="A3serial">
        <item>19190</item>
        <item>19191</item>
        <item>19192</item>
        <item>a19192</item>
        <item>19193</item>
        <item>19195</item>
        <item>19196</item>
    </string-array>

以下是触发崩溃的相关代码:

case R.id.btnSubModel:
        id =res.getIdentifier(chosenModel, "array", getActivity().getPackageName());
        data[0] = res.getStringArray(id);
        adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, data[0]);
        dialog.setTitle("Select Sub-Model");

这是我得到的异常的堆栈跟踪:

E/AndroidRuntime﹕ FATAL EXCEPTION: main
        Process: shuka_ins.co.il.shukainsuranceproject, PID: 2414
        android.content.res.Resources$NotFoundException: String array resource ID #0x0
                at android.content.res.Resources.getStringArray(Resources.java:502)
                at shuka_ins.co.il.shukainsuranceproject.CarFragment.onClick(CarFragment.java:199)
                at shuka_ins.co.il.shukainsuranceproject.CarFragment$3.onItemClick(CarFragment.java:189)
                at android.widget.AdapterView.performItemClick(AdapterView.java:300)
                at android.widget.AbsListView.performItemClick(AbsListView.java:1143)
                at android.widget.AbsListView$PerformClick.run(AbsListView.java:3044)

0 个答案:

没有答案