奇巧specific- android.content.res.Resources $ NotFoundException:从绘制资源ID文件RES /绘制/ list_selector_white.xml [英] KitKat specific- android.content.res.Resources$NotFoundException: File res/drawable/list_selector_white.xml from drawable resource ID
问题描述
我想答案<一个href=\"http://stackoverflow.com/questions/17701186/exception-android-content-res-resourcesnotfoundexception-file-res-drawable-my\">here,但它并没有为我工作。我使用XML作为背景并获得exceptiion - 资源$ NotFoundException:从绘制资源ID文件RES /绘制/ list_selector_white.xml
。该应用程序崩溃的发射。
I tried the answer here, but it didn't work for me. I am using an xml as background and getting exceptiion - Resources$NotFoundException: File res/drawable/list_selector_white.xml from drawable resource ID
. The app is crashing on launch.
怪异的部分是,它正在运行的设备棒棒糖罚款。在OS&LT; =奇巧,这个问题reproing
的XML这是在片段被充气
XML which is being inflated in fragment:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/list_selector_white" >
....Other views here....
list_selector_white.xml
list_selector_white.xml
<!-- Selector style for listrow -->
<item android:drawable="@drawable/gradient_bg_white" android:state_pressed="false" android:state_selected="false"/>
<item android:drawable="@drawable/gradient_bg_hover" android:state_pressed="true"/>
<item android:drawable="@drawable/gradient_bg_hover" android:state_pressed="false" android:state_selected="true"/>
gradient_bg_hover
gradient_bg_hover
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!-- Gradient BgColor for listrow Selected -->
<gradient
android:startColor="?attr/listViewRow"
android:centerColor="?attr/listViewRow"
android:endColor="?attr/listViewRow"
android:angle="270" />
</shape>
logcat的:
E/AndroidRuntime( 3879): android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
E/AndroidRuntime( 3879): at android.view.LayoutInflater.createView(LayoutInflater.java:620)
E/AndroidRuntime( 3879): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
E/AndroidRuntime( 3879): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
E/AndroidRuntime( 3879): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
E/AndroidRuntime( 3879): at android.view.LayoutInflater.inflate(LayoutInflater.java:469)
E/AndroidRuntime( 3879): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
E/AndroidRuntime( 3879): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
E/AndroidRuntime( 3879): at jsoup.LazyAdapterDoubleList.getView(LazyAdapterDoubleList.java:53)
E/AndroidRuntime( 3879): at android.widget.AbsListView.obtainView(AbsListView.java:2263)
E/AndroidRuntime( 3879): at android.widget.ListView.measureHeightOfChildren(ListView.java:1263)
E/AndroidRuntime( 3879): at android.widget.ListView.onMeasure(ListView.java:1175)
E/AndroidRuntime( 3879): at android.view.View.measure(View.java:16497)
E/AndroidRuntime( 3879): at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:719)
E/AndroidRuntime( 3879): at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:455)
E/AndroidRuntime( 3879): at android.view.View.measure(View.java:16497)
E/AndroidRuntime( 3879): at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:719)
E/AndroidRuntime( 3879): at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:455)
E/AndroidRuntime( 3879): at android.view.View.measure(View.java:16497)
E/AndroidRuntime( 3879): at android.support.v4.widget.SwipeRefreshLayout.onMeasure(SwipeRefreshLayout.java:577)
E/AndroidRuntime( 3879): at android.view.View.measure(View.java:16497)
E/AndroidRuntime( 3879): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
E/AndroidRuntime( 3879): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
E/AndroidRuntime( 3879): at android.view.View.measure(View.java:16497)
E/AndroidRuntime( 3879): at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:868)
E/AndroidRuntime( 3879): at android.view.View.measure(View.java:16497)
E/AndroidRuntime( 3879): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
E/AndroidRuntime( 3879): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
E/AndroidRuntime( 3879): at android.view.View.measure(View.java:16497)
E/AndroidRuntime( 3879): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
E/AndroidRuntime( 3879): at com.android.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:327)
E/AndroidRuntime( 3879): at android.view.View.measure(View.java:16497)
E/AndroidRuntime( 3879): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
E/AndroidRuntime( 3879): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
E/AndroidRuntime( 3879): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2291)
E/AndroidRuntime( 3879): at android.view.View.measure(View.java:16497)
E/AndroidRuntime( 3879): at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1916)
E/AndroidRuntime( 3879): at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1113)
E/AndroidRuntime( 3879): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1295)
E/AndroidRuntime( 3879): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000)
E/AndroidRuntime( 3879): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5670)
E/AndroidRuntime( 3879): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
E/AndroidRuntime( 3879): at android.view.Choreographer.doCallbacks(Choreographer.java:574)
E/AndroidRuntime( 3879): at android.view.Choreographer.doFrame(Choreographer.java:544)
E/AndroidRuntime( 3879): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
E/AndroidRuntime( 3879): at android.os.Handler.handleCallback(Handler.java:733)
E/AndroidRuntime( 3879): at android.os.Handler.dispatchMessage(Handler.java:95)
E/AndroidRuntime( 3879): at android.os.Looper.loop(Looper.java:136)
E/AndroidRuntime( 3879): at android.app.ActivityThread.main(ActivityThread.java:5017)
E/AndroidRuntime( 3879): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 3879): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
E/AndroidRuntime( 3879): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
E/AndroidRuntime( 3879): Caused by: java.lang.reflect.InvocationTargetException
E/AndroidRuntime( 3879): at java.lang.reflect.Constructor.newInstance(Native Method)
E/AndroidRuntime( 3879): at android.view.LayoutInflater.createView(LayoutInflater.java:594)
E/AndroidRuntime( 3879): ... 50 more
E/AndroidRuntime( 3879): Caused by: android.content.res.Resources$NotFoundException: File res/drawable/list_selector_white.xml from drawable resource ID #0x7f02006a
E/AndroidRuntime( 3879): at android.content.res.Resources.loadDrawable(Resources.java:2096)
E/AndroidRuntime( 3879): at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
E/AndroidRuntime( 3879): at android.view.View.<init>(View.jav
W/ActivityManager( 589): Force finishing activity free.programming.programming/.MainActivity
W/ActivityManager( 589): Activity pause timeout for ActivityRecord{655864a8 u0 free.programming.programming/.MainActivity t49 f}
如何解决它的任何带头作用?
Any lead on how to fix it?
结果
我怀疑使用 ATTR
在绘制导致的问题。起初,我用简单的 @color /...
和一切工作正常。
I suspect using attr
in drawable is causing issues. Initially, I was using simple @color/...
and everything was working fine.
推荐答案
我终于能够解决这个问题。我会后回答,以便它可以帮助未来的读者。
I was finally able to fix the issue. I will post answer so that it may help future readers.
问题是,我们不能以项目给予ATTR值
和渐变
。我采取不同的XML文件的颜色固定的问题。
The problem is that we can't give attr values to item
and gradient
. I got the issue fixed by taking different xml files for colors.
我结束了使用不同版本list_selector_white_1和_2.xml到的:
I ended up using different versions of list_selector_white_1 and _2.xml to:
<!-- Selector style for listrow -->
<item android:drawable="@drawable/gradient_bg_white_1" android:state_pressed="false" android:state_selected="false"/>
<item android:drawable="@drawable/gradient_bg_hover_1" android:state_pressed="true"/>
<item android:drawable="@drawable/gradient_bg_hover_1" android:state_pressed="false" android:state_selected="true"/>
同样,我改变了gradient_bg_hover和gradient_bg_white不同的版本。
Similarly, I changed gradient_bg_hover and gradient_bg_white to different versions.
最后,我创建了一个属性list_selector与格式整数
和XML片段用它:
Finally, I created an attribute list_selector with format integer
and used it in fragment xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="?attr/list_selector" >
....Other views here....
我在等待时,我可以支持API级别> = 21我的应用程序,以消除所有这些黑客的时间。
I am waiting for the time when I can support API level >= 21 in my app, in order to remove all these hacks.
这篇关于奇巧specific- android.content.res.Resources $ NotFoundException:从绘制资源ID文件RES /绘制/ list_selector_white.xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!