0

我在使用 android 2.2 的应用程序中遇到错误。错误如下:

java.lang.RuntimeException: Unable to start activity ComponentInfo{dev.luizmoratelli.cowpea.three.m.ui/dev.luizmoratelli.cowpea.three.m.ui.Preferences}: android.view.InflateException: Binary XML file line #20: Error inflating class android.widget.ListView

最奇怪的是,在我的 4.0.4 android 设备中它运行良好。

我的xml如下:

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
    <EditTextPreference
        android:key="pref_ip"
        android:title="IP do Servidor"
        android:defaultValue="0.0.0.0" />
</PreferenceScreen>

我的页面的 onCreate 如下:

@SuppressWarnings("deprecation")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.preferences);

        Preference prefIP = getPreferenceScreen().findPreference(KEY_PREF_IP);
        prefIP.setOnPreferenceChangeListener(validaIPListener);

        SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
        prefIP.setSummary(sharedPreferences.getString(KEY_PREF_IP, "0.0.0.0"));
    }

- 编辑 -

我发布了完整的 LogCat 日志,并在我的 styles.xml 下方:

11-29 22:18:26.940: E/ResourceType(343): Style contains key with bad entry: 0x010102f0
11-29 22:18:29.210: D/dalvikvm(343): GC_FOR_MALLOC freed 2953 objects / 267104 bytes in 69ms
11-29 22:18:29.770: E/ResourceType(343): Style contains key with bad entry: 0x010102f0
11-29 22:18:29.890: D/AndroidRuntime(343): Shutting down VM
11-29 22:18:29.890: W/dalvikvm(343): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
11-29 22:18:29.930: E/AndroidRuntime(343): FATAL EXCEPTION: main
11-29 22:18:29.930: E/AndroidRuntime(343): java.lang.RuntimeException: Unable to start activity ComponentInfo{dev.luizmoratelli.cowpea.three.m.ui/dev.luizmoratelli.cowpea.three.m.ui.Preferences}: android.view.InflateException: Binary XML file line #20: Error inflating class android.widget.ListView
11-29 22:18:29.930: E/AndroidRuntime(343):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
11-29 22:18:29.930: E/AndroidRuntime(343):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
11-29 22:18:29.930: E/AndroidRuntime(343):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
11-29 22:18:29.930: E/AndroidRuntime(343):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
11-29 22:18:29.930: E/AndroidRuntime(343):  at android.os.Handler.dispatchMessage(Handler.java:99)
11-29 22:18:29.930: E/AndroidRuntime(343):  at android.os.Looper.loop(Looper.java:123)
11-29 22:18:29.930: E/AndroidRuntime(343):  at android.app.ActivityThread.main(ActivityThread.java:4627)
11-29 22:18:29.930: E/AndroidRuntime(343):  at java.lang.reflect.Method.invokeNative(Native Method)
11-29 22:18:29.930: E/AndroidRuntime(343):  at java.lang.reflect.Method.invoke(Method.java:521)
11-29 22:18:29.930: E/AndroidRuntime(343):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-29 22:18:29.930: E/AndroidRuntime(343):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-29 22:18:29.930: E/AndroidRuntime(343):  at dalvik.system.NativeStart.main(Native Method)
11-29 22:18:29.930: E/AndroidRuntime(343): Caused by: android.view.InflateException: Binary XML file line #20: Error inflating class android.widget.ListView
11-29 22:18:29.930: E/AndroidRuntime(343):  at android.view.LayoutInflater.createView(LayoutInflater.java:513)
11-29 22:18:29.930: E/AndroidRuntime(343):  at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
11-29 22:18:29.930: E/AndroidRuntime(343):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
11-29 22:18:29.930: E/AndroidRuntime(343):  at android.view.LayoutInflater.inflate(LayoutInflater.java:385)
11-29 22:18:29.930: E/AndroidRuntime(343):  at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
11-29 22:18:29.930: E/AndroidRuntime(343):  at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
11-29 22:18:29.930: E/AndroidRuntime(343):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
11-29 22:18:29.930: E/AndroidRuntime(343):  at android.app.Activity.setContentView(Activity.java:1647)
11-29 22:18:29.930: E/AndroidRuntime(343):  at android.preference.PreferenceActivity.onCreate(PreferenceActivity.java:107)
11-29 22:18:29.930: E/AndroidRuntime(343):  at dev.luizmoratelli.cowpea.three.m.ui.Preferences.onCreate(Preferences.java:52)
11-29 22:18:29.930: E/AndroidRuntime(343):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-29 22:18:29.930: E/AndroidRuntime(343):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
11-29 22:18:29.930: E/AndroidRuntime(343):  ... 11 more
11-29 22:18:29.930: E/AndroidRuntime(343): Caused by: java.lang.reflect.InvocationTargetException
11-29 22:18:29.930: E/AndroidRuntime(343):  at android.widget.ListView.<init>(ListView.java:153)
11-29 22:18:29.930: E/AndroidRuntime(343):  at java.lang.reflect.Constructor.constructNative(Native Method)
11-29 22:18:29.930: E/AndroidRuntime(343):  at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
11-29 22:18:29.930: E/AndroidRuntime(343):  at android.view.LayoutInflater.createView(LayoutInflater.java:500)
11-29 22:18:29.930: E/AndroidRuntime(343):  ... 22 more
11-29 22:18:29.930: E/AndroidRuntime(343): Caused by: android.content.res.Resources$NotFoundException: File res/drawable-mdpi/darkbluegradientc3m.xml from color state list resource ID #0x7f020007
11-29 22:18:29.930: E/AndroidRuntime(343):  at android.content.res.Resources.loadColorStateList(Resources.java:1817)
11-29 22:18:29.930: E/AndroidRuntime(343):  at android.content.res.TypedArray.getColor(TypedArray.java:319)
11-29 22:18:29.930: E/AndroidRuntime(343):  at android.widget.AbsListView.<init>(AbsListView.java:554)
11-29 22:18:29.930: E/AndroidRuntime(343):  at android.widget.ListView.<init>(ListView.java:157)
11-29 22:18:29.930: E/AndroidRuntime(343):  ... 26 more
11-29 22:18:29.930: E/AndroidRuntime(343): Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #1: invalid drawable tag shape
11-29 22:18:29.930: E/AndroidRuntime(343):  at android.content.res.ColorStateList.createFromXmlInner(ColorStateList.java:144)
11-29 22:18:29.930: E/AndroidRuntime(343):  at android.content.res.ColorStateList.createFromXml(ColorStateList.java:127)
11-29 22:18:29.930: E/AndroidRuntime(343):  at android.content.res.Resources.loadColorStateList(Resources.java:1814)
11-29 22:18:29.930: E/AndroidRuntime(343):  ... 29 more

<resources xmlns:android="http://schemas.android.com/apk/res/android">

    <style name="BlueTheme" parent="@android:style/Theme">
        <item name="android:windowBackground">@drawable/darkbluegradientc3m</item>
        <item name="android:colorBackground">@drawable/darkbluegradientc3m</item>
        <item name="android:dropDownListViewStyle">@style/spinner_list_view</item>
        <item name="android:listChoiceBackgroundIndicator">@drawable/list_selector_c3m</item>
    </style>

    <style name="text_title" parent="@android:style/Widget.TextView">
        <item name="android:textColor">#E5E6FF</item>
        <item name="android:layout_width">wrap_content</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:textSize">30sp</item>
        <item name="android:layout_gravity">center</item>
    </style>

    <style name="text_regular" parent="@android:style/Widget.TextView">
        <item name="android:textColor">#AADDFF</item>
        <item name="android:layout_width">wrap_content</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:layout_marginTop">10dp</item>
        <item name="android:textSize">20sp</item>
        <item name="android:layout_marginLeft">10dp</item>
    </style>

    <style name="text_dropdownitem" parent="@android:style/Widget.DropDownItem">
        <item name="android:textColor">#AADDFF</item>
        <item name="android:textSize">20sp</item>
    </style>

    <style name="button" parent="@android:style/Widget.Button">
        <item name="android:layout_width">fill_parent</item>
        <item name="android:layout_marginLeft">40dp</item>
        <item name="android:layout_marginRight">40dp</item>
        <item name="android:layout_marginTop">20dp</item>
        <item name="android:textColor">@android:color/white</item>
        <item name="android:background">@drawable/roundedbutton</item>
        <item name="android:textSize">20sp</item>
    </style>

    <style name="buttonLogin" parent="@style/button">
        <item name="android:layout_height">80dp</item>
    </style>

    <style name="buttonMenu" parent="@style/button">
        <item name="android:layout_height">70dp</item>
    </style>

    <style name="editText" parent="@android:style/Widget.EditText">
        <item name="android:layout_width">match_parent</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:ems">10</item>
    </style>

    <style name="spinner" parent="@android:style/Widget.Spinner">
        <item name="android:layout_width">match_parent</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:spinnerMode">dropdown</item>
        <item name="android:popupBackground">@drawable/darkbluegradientroundedc3m</item>
    </style>

        <style name="spinner_list_view" parent="@android:style/Widget.DropDownItem.Spinner">
        <item name="android:divider">#696969</item>
        <item name="android:dividerHeight">1dp</item>
    </style>

</resources>

--EDIT2-- 来自 darkbluegradientec3m.xml 的 xml

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient
        android:angle="90"
        android:startColor="#FF16163D"
        android:endColor="#FF010105"
        android:type="linear"
        />
</shape>
4

1 回答 1

1

BlueTheme中的标签colorBackground似乎有问题,因为文档需要颜色值,如#abc或指向它们的链接。可能不同版本的 Android 对这个标签的解析不同。尝试使用简单的颜色值,而不是可绘制对象。

此外,您的标签listChoiceBackgroundIndicator将无法在具有 API 11< 的 android 上运行。

于 2012-11-29T23:28:05.153 回答