简体   繁体   English

由于Resources $ NotFoundException,应用程序在启动时在Android API 10上崩溃,但在API 16上没有崩溃

[英]App crashes on startup on android API 10 but not on API 16 because of Resources$NotFoundException

My app launches and starts fine on my Samsung Galaxy S3 phone running Android 4.1.2, but when I try to test the same app on my Motorola Droid X running Android 2.3.4 the app crashes before anything is even displayed on my Droid X screen. 我的应用程序在运行Android 4.1.2的三星Galaxy S3手机上启动并启动,但是当我尝试在运行Android 2.3.4的摩托罗拉Droid X上测试相同的应用程序时,应用程序崩溃,甚至在我的Droid X屏幕上显示任何内容。

My LogCat is below. 我的LogCat在下面。 Unfortunately, it does not point me to exactly what part of my code it is failing on, but it seems like something to do with my layout because of these exceptions: 不幸的是,它没有指出我的代码究竟是哪个部分失败了,但是由于以下异常,它似乎与我的布局有关:

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}

Log Cat: Log Cat:

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

Fixed!! 固定!!

Looking into it more and it looks like it had something to do with the ArrayAdapter as well as my layout. 进一步研究它看起来与ArrayAdapter以及我的布局有关。 I was using a custom layout (drawer_list_item.xml) for my ArrayAdapter which had some ICS specific code I am guessing, so I just had to remove some lines from that XML file and the app launched fine on Android API 10 (specifically Android 2.3.4). 我正在为我的ArrayAdapter使用自定义布局(drawer_list_item.xml),它有一些我猜的ICS特定代码,所以我只需从该XML文件中删除一些行,并在Android API 10(特别是Android 2.3)上启动应用程序。 4)。 The lines specifically in my layout file that caused problems was: 我的布局文件中特别导致问题的行是:

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

Here is the code in my SherlockFragmentActivity that was causing the layout exception/crash: 以下是我的SherlockFragmentActivity中导致布局异常/崩溃的代码:

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

OLD drawer_list_item.xml code: OLD 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-->

FIXED drawer_list_item.xml code: 修复了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" />

Are you using ActionBarSherlock or HoloEverywhere? 您使用的是ActionBarSherlock还是HoloEverywhere? I've experienced this problem a lot when using those libraries and trying to style/theme things. 在使用这些库并尝试设计样式/主题时,我经历了很多这个问题。

Basically, some attributes are specified by default in ICS+, but are not specified in older versions of android. 基本上,某些属性在ICS +中默认指定,但在旧版本的android中未指定。 So, you have to mirror resources, as shown here: http://actionbarsherlock.com/theming.html 因此,您必须镜像资源,如下所示: http//actionbarsherlock.com/theming.html

Posting your code for the themes/styles might be helpful for us to see whats wrong. 发布主题/样式的代码可能有助于我们查看错误。

Without more code I cannot tell you exactly why the app is failing. 如果没有更多代码,我无法确切地告诉您应用程序失败的原因。 All we know is that you might use some feature available only for higher APIs. 我们所知道的是,您可能会使用某些仅适用于更高API的功能。 Post your xml-layouts and maybe your classes. 发布你的xml-layouts,也许你的课程。

However, try to include the Support Library. 但是,请尝试包含支持库。 That often solves the problem. 这通常可以解决问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 android.content.res.Resources $ NotFoundException在启动时,仅在api 23及以下版本中 - android.content.res.Resources$NotFoundException on startup, only in api 23 and below Worklight应用程序崩溃,错误android.content.res.Resources $ NotFoundException - Worklight app crashes with error android.content.res.Resources$NotFoundException Android 10 设备上的 Resources$NotFoundException - Resources$NotFoundException on Android 10 devices Android App使用AppCompatActivity API16崩溃 - Android App Crashes using AppCompatActivity API16 应用程序在Android 5.1和6.1中运行良好,但在4.10(API 16)中崩溃 - App works well in android 5.1 and 6.1 but crashes in 4.10(API 16) android.content.res.Resources $ NotFoundException API级别19 - android.content.res.Resources$NotFoundException API Level 19 api19上的android.content.res.Resources $ NotFoundException - android.content.res.Resources$NotFoundException on api19 Android Resources$NotFoundException 来自旧手机 API 18 的可绘制资源 - Android Resources$NotFoundException from drawable resource for older phones API 18 Android Studio 导入的 SVG 文件(生成的 XML)使应用程序崩溃(引起:android.content.res.Resources$NotFoundException) - Android Studio Imported SVG file (resulting XML) crashes the app (Caused by: android.content.res.Resources$NotFoundException) 切换到 Android 应用程序包分发后,应用程序有时会因 Resources$NotFoundException 崩溃 - App sometimes crashes with Resources$NotFoundException after switching to android app bundle distribution
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM