我正在努力寻找解决此错误的方法:
02-20 19:50:36.027: E/AndroidRuntime(26842): FATAL EXCEPTION: main
02-20 19:50:36.027: E/AndroidRuntime(26842): android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
02-20 19:50:36.027: E/AndroidRuntime(26842): at android.view.LayoutInflater.createView(LayoutInflater.java)
02-20 19:50:36.027: E/AndroidRuntime(26842): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java)
02-20 19:50:36.027: E/AndroidRuntime(26842): at android.view.LayoutInflater.onCreateView(LayoutInflater.java)
02-20 19:50:36.027: E/AndroidRuntime(26842): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java)
02-20 19:50:36.027: E/AndroidRuntime(26842): at android.view.LayoutInflater.inflate(LayoutInflater.java)
02-20 19:50:36.027: E/AndroidRuntime(26842): at android.view.LayoutInflater.inflate(LayoutInflater.java)
02-20 19:50:36.027: E/AndroidRuntime(26842): at android.view.LayoutInflater.inflate(LayoutInflater.java)
02-20 19:50:36.027: E/AndroidRuntime(26842): at Utility.AdapterListaLinee.getView(AdapterListaLinee.java:59)
02-20 19:50:36.027: E/AndroidRuntime(26842): at android.widget.AbsListView.obtainView(AbsListView.java)
02-20 19:50:36.027: E/AndroidRuntime(26842): at android.widget.ListView.makeAndAddView(ListView.java)
02-20 19:50:36.027: E/AndroidRuntime(26842): at android.widget.ListView.fillDown(ListView.java)
02-20 19:50:36.027: E/AndroidRuntime(26842): at android.widget.ListView.fillFromTop(ListView.java)
02-20 19:50:36.027: E/AndroidRuntime(26842): at android.widget.ListView.layoutChildren(ListView.java)
02-20 19:50:36.027: E/AndroidRuntime(26842): at android.widget.AbsListView.onLayout(AbsListView.java)
02-20 19:50:36.027: E/AndroidRuntime(26842): at android.view.View.layout(View.java)
02-20 19:50:36.027: E/AndroidRuntime(26842): at android.view.ViewGroup.layout(ViewGroup.java)
02-20 19:50:36.027: E/AndroidRuntime(26842): at android.widget.RelativeLayout.onLayout(RelativeLayout.java)
02-20 19:50:36.027: E/AndroidRuntime(26842): at android.view.View.layout(View.java)
02-20 19:50:36.027: E/AndroidRuntime(26842): at android.view.ViewGroup.layout(ViewGroup.java)
02-20 19:50:36.027: E/AndroidRuntime(26842): at android.widget.FrameLayout.onLayout(FrameLayout.java)
02-20 19:50:36.027: E/AndroidRuntime(26842): at android.view.View.layout(View.java)
02-20 19:50:36.027: E/AndroidRuntime(26842): at android.view.ViewGroup.layout(ViewGroup.java)
02-20 19:50:36.027: E/AndroidRuntime(26842): at android.widget.FrameLayout.onLayout(FrameLayout.java)
02-20 19:50:36.027: E/AndroidRuntime(26842): at android.view.View.layout(View.java)
02-20 19:50:36.027: E/AndroidRuntime(26842): at android.view.ViewGroup.layout(ViewGroup.java)
02-20 19:50:36.027: E/AndroidRuntime(26842): at android.widget.FrameLayout.onLayout(FrameLayout.java)
02-20 19:50:36.027: E/AndroidRuntime(26842): at android.view.View.layout(View.java)
02-20 19:50:36.027: E/AndroidRuntime(26842): at android.view.ViewGroup.layout(ViewGroup.java)
02-20 19:50:36.027: E/AndroidRuntime(26842): at android.widget.FrameLayout.onLayout(FrameLayout.java)
02-20 19:50:36.027: E/AndroidRuntime(26842): at android.view.View.layout(View.java)
02-20 19:50:36.027: E/AndroidRuntime(26842): at android.view.ViewGroup.layout(ViewGroup.java)
02-20 19:50:36.027: E/AndroidRuntime(26842): at android.widget.FrameLayout.onLayout(FrameLayout.java)
02-20 19:50:36.027: E/AndroidRuntime(26842): at android.view.View.layout(View.java)
02-20 19:50:36.027: E/AndroidRuntime(26842): at android.view.ViewGroup.layout(ViewGroup.java)
02-20 19:50:36.027: E/AndroidRuntime(26842): at android.view.ViewRootImpl.performLayout(ViewRootImpl.java)
02-20 19:50:36.027: E/AndroidRuntime(26842): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java)
02-20 19:50:36.027: E/AndroidRuntime(26842): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java)
02-20 19:50:36.027: E/AndroidRuntime(26842): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java)
02-20 19:50:36.027: E/AndroidRuntime(26842): at android.view.Choreographer$CallbackRecord.run(Choreographer.java)
02-20 19:50:36.027: E/AndroidRuntime(26842): at android.view.Choreographer.doCallbacks(Choreographer.java)
02-20 19:50:36.027: E/AndroidRuntime(26842): at android.view.Choreographer.doFrame(Choreographer.java)
02-20 19:50:36.027: E/AndroidRuntime(26842): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java)
02-20 19:50:36.027: E/AndroidRuntime(26842): at android.os.Handler.handleCallback(Handler.java)
02-20 19:50:36.027: E/AndroidRuntime(26842): at android.os.Handler.dispatchMessage(Handler.java)
02-20 19:50:36.027: E/AndroidRuntime(26842): at android.os.Looper.loop(Looper.java)
02-20 19:50:36.027: E/AndroidRuntime(26842): at android.app.ActivityThread.main(ActivityThread.java)
02-20 19:50:36.027: E/AndroidRuntime(26842): at java.lang.reflect.Method.invokeNative(Native Method)
02-20 19:50:36.027: E/AndroidRuntime(26842): at java.lang.reflect.Method.invoke(Method.java)
02-20 19:50:36.027: E/AndroidRuntime(26842): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java)
02-20 19:50:36.027: E/AndroidRuntime(26842): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java)
02-20 19:50:36.027: E/AndroidRuntime(26842): at dalvik.system.NativeStart.main(Native Method)
02-20 19:50:36.027: E/AndroidRuntime(26842): Caused by: java.lang.reflect.InvocationTargetException
02-20 19:50:36.027: E/AndroidRuntime(26842): at java.lang.reflect.Constructor.constructNative(Native Method)
02-20 19:50:36.027: E/AndroidRuntime(26842): at java.lang.reflect.Constructor.newInstance(Constructor.java)
02-20 19:50:36.027: E/AndroidRuntime(26842): ... 51 more
02-20 19:50:36.027: E/AndroidRuntime(26842): Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x2/d=0x7f010070 a=-1}
02-20 19:50:36.027: E/AndroidRuntime(26842): at android.content.res.Resources.loadDrawable(Resources.java)
02-20 19:50:36.027: E/AndroidRuntime(26842): at android.content.res.TypedArray.getDrawable(TypedArray.java)
02-20 19:50:36.027: E/AndroidRuntime(26842): at android.view.View.<init>(View.java)
02-20 19:50:36.027: E/AndroidRuntime(26842): at android.view.View.<init>(View.java)
02-20 19:50:36.027: E/AndroidRuntime(26842): at android.view.ViewGroup.<init>(ViewGroup.java)
02-20 19:50:36.027: E/AndroidRuntime(26842): at android.widget.RelativeLayout.<init>(RelativeLayout.java)
02-20 19:50:36.027: E/AndroidRuntime(26842): ... 53 more
来自 styles.xml 的一些相关代码:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppTheme" parent="Theme.Sherlock.Light.DarkActionBar">
<item name="android:windowActionBarOverlay">true</item>
<item name="android:windowActionModeOverlay">true</item>
<item name="android:actionBarStyle">@style/ActionBar</item>
<item name="ColSfondo">#00000000</item>
<item name="ColSfondoVociListe">@drawable/SfondoVociListe</item>
<item name="ColSfondoVoceInfotraffico">#00000000</item>
<item name="ColTestoFields">#ff000000</item>
<item name="ColTestoVociListe">@drawable/ColoreTestoVoci</item>
</style>
<style name="AppThemeDark" parent="Theme.Sherlock.Light.DarkActionBar">
<item name="android:windowActionBarOverlay">true</item>
<item name="android:windowActionModeOverlay">true</item>
<item name="android:actionBarStyle">@style/ActionBar</item>
<item name="ColSfondo">@drawable/holo_background_gradient</item>
<item name="ColSfondoVociListe">#00000000</item>
<item name="ColSfondoVoceInfotraffico">@drawable/holo_background_gradient</item>
<item name="ColTestoFields">#ffffffff</item>
<item name="ColTestoVociListe">@drawable/ColoreTestoVoci</item>
</style>
<attr name="ColSfondo" format="color|reference" />
<attr name="ColSfondoVociListe" format="color|reference" />
<attr name="ColSfondoVoceInfotraffico" format="color|reference" />
<attr name="ColTestoFields" format="color|reference" />
<attr name="ColTestoVociListe" format="color|reference" />
<drawable name="ColoreTestoVoci">#ffffffff</drawable>
<drawable name="SfondoVociListe">#dd212121</drawable>
<color name="ColoreSecondarioVoci">#ffdddddd</color>
[...]
</resources>
这是导致问题的 xlm 布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/ColSfondoVociListe" >
<ImageView
android:id="@+id/ListaLineeImage"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="@drawable/ic_lista" />
<TextView
android:id="@+id/ListaLineeTitolo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_toRightOf="@+id/ListaLineeImage"
android:gravity="center_vertical"
android:text="Medium Text"
android:textColor="?ColTestoVociListe"
android:textSize="@dimen/Titolo" />
</RelativeLayout>
如果我删除“?ColTestoVociListe”和“?attr/ColSfondoVociListe”,用#aarrggbb 之类的颜色替换它们就可以了。但我需要使用属性来改变颜色和主题。在其他 xml 文件中,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/ColSfondoVociListe" >
[.....]
</RelativeLayout>
没有错误被抛出!!!!为什么????相同的属性,拼写完全相同。我尝试了很多次删除和重新创建 R.java 并清理项目。请帮我。