Android - setContentView 中的 loadDrawableForCookie Resources$NotFoundException
Posted
技术标签:
【中文标题】Android - setContentView 中的 loadDrawableForCookie Resources$NotFoundException【英文标题】:Android - loadDrawableForCookie Resources$NotFoundException in setContentView 【发布时间】:2020-09-17 22:13:23 【问题描述】:当在 Activity.onCreate()
中调用 setContentView()
时,在某些 android 6.0 设备上会发生此崩溃
java.lang.RuntimeException:
at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:3319)
at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3415)
at android.app.ActivityThread.access$1100 (ActivityThread.java:229)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1821)
at android.os.Handler.dispatchMessage (Handler.java:102)
at android.os.Looper.loop (Looper.java:148)
at android.app.ActivityThread.main (ActivityThread.java:7325)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1120)
Caused by: android.view.InflateException:
at android.view.LayoutInflater.inflate (LayoutInflater.java:551)
at android.view.LayoutInflater.inflate (LayoutInflater.java:429)
at android.view.LayoutInflater.inflate (LayoutInflater.java:380)
at com.android.internal.policy.PhoneWindow.setContentView (PhoneWindow.java:479)
at android.app.Activity.setContentView (Activity.java:2400)
at MyActivity.onCreate (MyActivity.java:42)
at android.app.Activity.performCreate (Activity.java:6904)
at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1136)
at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:3266)
Caused by: android.view.InflateException:
at android.view.LayoutInflater.createView (LayoutInflater.java:657)
at com.android.internal.policy.PhoneLayoutInflater.onCreateView (PhoneLayoutInflater.java:58)
at android.view.LayoutInflater.onCreateView (LayoutInflater.java:706)
at android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:774)
at android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:716)
at android.view.LayoutInflater.rInflate (LayoutInflater.java:847)
at android.view.LayoutInflater.rInflateChildren (LayoutInflater.java:810)
at android.view.LayoutInflater.rInflate (LayoutInflater.java:855)
at android.view.LayoutInflater.inflate (LayoutInflater.java:495)
Caused by: java.lang.reflect.InvocationTargetException:
at java.lang.reflect.Constructor.newInstance (Native Method)
at android.view.LayoutInflater.createView (LayoutInflater.java:631)
Caused by: android.content.res.Resources$NotFoundException:
at android.content.res.Resources.loadDrawableForCookie (Resources.java:4289)
at android.content.res.Resources.loadDrawable (Resources.java:4158)
at android.content.res.Resources.loadDrawable (Resources.java:4003)
at android.content.res.TypedArray.getDrawable (TypedArray.java:886)
at android.view.View.<init> (View.java:4242)
at android.widget.TextView.<init> (TextView.java:961)
at android.widget.Button.<init> (Button.java:112)
at android.widget.Button.<init> (Button.java:105)
at android.widget.Button.<init> (Button.java:101)
Caused by: org.xmlpull.v1.XmlPullParserException:
at android.graphics.drawable.StateListDrawable.inflateChildElements (StateListDrawable.java:182)
at android.graphics.drawable.StateListDrawable.inflate (StateListDrawable.java:115)
at android.graphics.drawable.Drawable.createFromXmlInner (Drawable.java:2551)
at android.graphics.drawable.Drawable.createFromXml (Drawable.java:2322)
at android.content.res.Resources.loadDrawableForCookie (Resources.java:4279)
是否有解决此问题的方法或解决方法?
【问题讨论】:
【参考方案1】:我认为您在 setContentView 方法中传递了一个空布局/视图。你能附上你传递的方法和参数吗?
【讨论】:
以上是关于Android - setContentView 中的 loadDrawableForCookie Resources$NotFoundException的主要内容,如果未能解决你的问题,请参考以下文章
Android 9 (API 28) 活动在启动时崩溃 (setContentView)