由于Resources $ NotFoundException,应用程序在android API 10上启动时崩溃,而在API 16上崩溃

我的应用程序启动并开始运行Android 4.1.2的三星Galaxy S3手机罚款,但当我尝试testing我的摩托罗拉Droid X运行Android 2.3.4上的应用程序相同的应用程序崩溃之前甚至显示在我的Droid X屏幕上。

我的LogCat在下面。 不幸的是,它并没有指出我的代码究竟是哪一部分失败了,但是由于这些例外,这似乎与我的布局有关:

08-09 10:43:39.686: E/AndroidRuntime(3192): FATAL EXCEPTION: main 08-09 10:43:39.686: E/AndroidRuntime(3192): android.view.InflateException: Binary XML file line #11: Error inflating class <unknown> 08-09 10:43:39.686: E/AndroidRuntime(3192): Caused by: java.lang.reflect.InvocationTargetException` 08-09 10:43:39.686: E/AndroidRuntime(3192): Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x2/d=0x10102fd a=-1} 

login猫:

 08-09 10:43:39.686: E/AndroidRuntime(3192): FATAL EXCEPTION: main 08-09 10:43:39.686: E/AndroidRuntime(3192): android.view.InflateException: Binary XML file line #11: Error inflating class <unknown> 08-09 10:43:39.686: E/AndroidRuntime(3192): at android.view.LayoutInflater.createView(LayoutInflater.java:518) 08-09 10:43:39.686: E/AndroidRuntime(3192): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56) 08-09 10:43:39.686: E/AndroidRuntime(3192): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568) 08-09 10:43:39.686: E/AndroidRuntime(3192): at android.view.LayoutInflater.inflate(LayoutInflater.java:386) 08-09 10:43:39.686: E/AndroidRuntime(3192): at android.view.LayoutInflater.inflate(LayoutInflater.java:320) 08-09 10:43:39.686: E/AndroidRuntime(3192): at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:332) 08-09 10:43:39.686: E/AndroidRuntime(3192): at android.widget.ArrayAdapter.getView(ArrayAdapter.java:323) 08-09 10:43:39.686: E/AndroidRuntime(3192): at android.widget.AbsListView.obtainView(AbsListView.java:1456) 08-09 10:43:39.686: E/AndroidRuntime(3192): at android.widget.ListView.makeAndAddView(ListView.java:1821) 08-09 10:43:39.686: E/AndroidRuntime(3192): at android.widget.ListView.fillDown(ListView.java:686) 08-09 10:43:39.686: E/AndroidRuntime(3192): at android.widget.ListView.fillFromTop(ListView.java:754) 08-09 10:43:39.686: E/AndroidRuntime(3192): at android.widget.ListView.layoutChildren(ListView.java:1670) 08-09 10:43:39.686: E/AndroidRuntime(3192): at android.widget.AbsListView.onLayout(AbsListView.java:1286) 08-09 10:43:39.686: E/AndroidRuntime(3192): at android.view.View.layout(View.java:7184) 08-09 10:43:39.686: E/AndroidRuntime(3192): at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:702) 08-09 10:43:39.686: E/AndroidRuntime(3192): at android.view.View.layout(View.java:7184) 08-09 10:43:39.686: E/AndroidRuntime(3192): at android.widget.FrameLayout.onLayout(FrameLayout.java:338) 08-09 10:43:39.686: E/AndroidRuntime(3192): at android.view.View.layout(View.java:7184) 08-09 10:43:39.686: E/AndroidRuntime(3192): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254) 08-09 10:43:39.686: E/AndroidRuntime(3192): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130) 08-09 10:43:39.686: E/AndroidRuntime(3192): at android.widget.LinearLayout.onLayout(LinearLayout.java:1047) 08-09 10:43:39.686: E/AndroidRuntime(3192): at android.view.View.layout(View.java:7184) 08-09 10:43:39.686: E/AndroidRuntime(3192): at android.widget.FrameLayout.onLayout(FrameLayout.java:338) 08-09 10:43:39.686: E/AndroidRuntime(3192): at android.view.View.layout(View.java:7184) 08-09 10:43:39.686: E/AndroidRuntime(3192): at android.widget.FrameLayout.onLayout(FrameLayout.java:338) 08-09 10:43:39.686: E/AndroidRuntime(3192): at android.view.View.layout(View.java:7184) 08-09 10:43:39.686: E/AndroidRuntime(3192): at android.view.ViewRoot.performTraversals(ViewRoot.java:1140) 08-09 10:43:39.686: E/AndroidRuntime(3192): at android.view.ViewRoot.handleMessage(ViewRoot.java:1859) 08-09 10:43:39.686: E/AndroidRuntime(3192): at android.os.Handler.dispatchMessage(Handler.java:99) 08-09 10:43:39.686: E/AndroidRuntime(3192): at android.os.Looper.loop(Looper.java:130) 08-09 10:43:39.686: E/AndroidRuntime(3192): at android.app.ActivityThread.main(ActivityThread.java:3806) 08-09 10:43:39.686: E/AndroidRuntime(3192): at java.lang.reflect.Method.invokeNative(Native Method) 08-09 10:43:39.686: E/AndroidRuntime(3192): at java.lang.reflect.Method.invoke(Method.java:507) 08-09 10:43:39.686: E/AndroidRuntime(3192): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 08-09 10:43:39.686: E/AndroidRuntime(3192): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 08-09 10:43:39.686: E/AndroidRuntime(3192): at dalvik.system.NativeStart.main(Native Method) 08-09 10:43:39.686: E/AndroidRuntime(3192): Caused by: java.lang.reflect.InvocationTargetException 08-09 10:43:39.686: E/AndroidRuntime(3192): at java.lang.reflect.Constructor.constructNative(Native Method) 08-09 10:43:39.686: E/AndroidRuntime(3192): at java.lang.reflect.Constructor.newInstance(Constructor.java:415) 08-09 10:43:39.686: E/AndroidRuntime(3192): at android.view.LayoutInflater.createView(LayoutInflater.java:505) 08-09 10:43:39.686: E/AndroidRuntime(3192): ... 35 more 08-09 10:43:39.686: E/AndroidRuntime(3192): Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x2/d=0x10102fd a=-1} 08-09 10:43:39.686: E/AndroidRuntime(3192): at android.content.res.Resources.loadDrawable(Resources.java:1719) 08-09 10:43:39.686: E/AndroidRuntime(3192): at android.content.res.TypedArray.getDrawable(TypedArray.java:601) 08-09 10:43:39.686: E/AndroidRuntime(3192): at android.view.View.<init>(View.java:1951) 08-09 10:43:39.686: E/AndroidRuntime(3192): at android.widget.TextView.<init>(TextView.java:453) 08-09 10:43:39.686: E/AndroidRuntime(3192): at android.widget.TextView.<init>(TextView.java:446) 08-09 10:43:39.686: E/AndroidRuntime(3192): ... 38 more 08-09 10:43:42.201: I/Process(3192): Sending signal. PID: 3192 SIG: 9 

Solutions Collecting From Web of "由于Resources $ NotFoundException,应用程序在android API 10上启动时崩溃,而在API 16上崩溃"

固定!!

仔细看看它,看起来它和ArrayAdapter以及我的布局有关。 我为我的ArrayAdapter使用了一个自定义的布局(drawer_list_item.xml),它有一些我猜测的ICS特定代码,所以我只需要从该XML文件中删除一些行,并在Android API 10(特别是Android 2.3)上启动应用程序。 4)。 在我的布局文件中,导致问题的具体行是:

 android:background="?android:attr/activatedBackgroundIndicator" android:minHeight="?android:attr/listPreferredItemHeightSmall" 

下面是导致布局exception/崩溃的SherlockFragmentActivity中的代码:

 m_drawerList.setAdapter(new ArrayAdapter<String>(getSupportActionBar().getThemedContext(),R.layout.drawer_list_item, m_drawerNames)); 

旧的drawer_list_item.xml代码:

 <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/text1" android:layout_width="match_parent" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceListItemSmall"<!-- Deleted line--> android:gravity="center_vertical" android:paddingLeft="16dp" android:paddingRight="16dp" android:textColor="#fff" android:background="?android:attr/activatedBackgroundIndicator"<!-- Deleted line--> android:minHeight="?android:attr/listPreferredItemHeightSmall"/> <!-- Deleted line--> 

固定的drawer_list_item.xml代码:

 <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/text1" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_vertical" android:padding="16dp" android:textColor="#fff" /> 

你在使用ActionBarSherlock还是HoloEverywhere? 在使用这些库并试图devise风格/主题时,我遇到过这个问题。

基本上,在ICS +中默认指定了一些属性,但在老版本的android中没有指定。 所以,你必须镜像资源,如下所示: http : //actionbarsherlock.com/theming.html

发布你的主题/风格的代码可能会有助于我们看到什么是错的。

没有更多的代码,我不能告诉你为什么应用程序失败。 我们所知道的是,您可能会使用仅适用于更高API的某些function。 发布你的XML布局,也许你的类。

但是,尝试包括支持库。 这通常解决了这个问题。