问题
I'm facing the given problem.
On galaxy s2 everything works well, on noname android 2.3 (phone and 7' tablet) - everythings is ok. But galaxy tab2 and note2 gives this error.
Here is the stack trace:
06-27 21:28:20.659: E/AndroidRuntime(23924): FATAL EXCEPTION: main
06-27 21:28:20.659: E/AndroidRuntime(23924): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myPackage.myProject/com.myPackage.myProject.MainActivity}: android.view.InflateException: Binary XML file line #39: Error inflating class <unknown>
06-27 21:28:20.659: E/AndroidRuntime(23924): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1968)
06-27 21:28:20.659: E/AndroidRuntime(23924): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1993)
06-27 21:28:20.659: E/AndroidRuntime(23924): at android.app.ActivityThread.access$600(ActivityThread.java:127)
06-27 21:28:20.659: E/AndroidRuntime(23924): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1159)
06-27 21:28:20.659: E/AndroidRuntime(23924): at android.os.Handler.dispatchMessage(Handler.java:99)
06-27 21:28:20.659: E/AndroidRuntime(23924): at android.os.Looper.loop(Looper.java:137)
06-27 21:28:20.659: E/AndroidRuntime(23924): at android.app.ActivityThread.main(ActivityThread.java:4507)
06-27 21:28:20.659: E/AndroidRuntime(23924): at java.lang.reflect.Method.invokeNative(Native Method)
06-27 21:28:20.659: E/AndroidRuntime(23924): at java.lang.reflect.Method.invoke(Method.java:511)
06-27 21:28:20.659: E/AndroidRuntime(23924): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:978)
06-27 21:28:20.659: E/AndroidRuntime(23924): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:745)
06-27 21:28:20.659: E/AndroidRuntime(23924): at dalvik.system.NativeStart.main(Native Method)
06-27 21:28:20.659: E/AndroidRuntime(23924): Caused by: android.view.InflateException: Binary XML file line #39: Error inflating class <unknown>
06-27 21:28:20.659: E/AndroidRuntime(23924): at android.view.LayoutInflater.createView(LayoutInflater.java:606)
06-27 21:28:20.659: E/AndroidRuntime(23924): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
06-27 21:28:20.659: E/AndroidRuntime(23924): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
06-27 21:28:20.659: E/AndroidRuntime(23924): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
06-27 21:28:20.659: E/AndroidRuntime(23924): at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
06-27 21:28:20.659: E/AndroidRuntime(23924): at android.view.LayoutInflater.parseInclude(LayoutInflater.java:798)
06-27 21:28:20.659: E/AndroidRuntime(23924): at android.view.LayoutInflater.rInflate(LayoutInflater.java:729)
06-27 21:28:20.659: E/AndroidRuntime(23924): at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
06-27 21:28:20.659: E/AndroidRuntime(23924): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
06-27 21:28:20.659: E/AndroidRuntime(23924): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
06-27 21:28:20.659: E/AndroidRuntime(23924): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
06-27 21:28:20.659: E/AndroidRuntime(23924): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:272)
06-27 21:28:20.659: E/AndroidRuntime(23924): at android.app.Activity.setContentView(Activity.java:1835)
06-27 21:28:20.659: E/AndroidRuntime(23924): at com.myPackage.myProject.MainActivity.onCreate(MainActivity.java:53)
06-27 21:28:20.659: E/AndroidRuntime(23924): at android.app.Activity.performCreate(Activity.java:4469)
06-27 21:28:20.659: E/AndroidRuntime(23924): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052)
06-27 21:28:20.659: E/AndroidRuntime(23924): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1932)
06-27 21:28:20.659: E/AndroidRuntime(23924): ... 11 more
06-27 21:28:20.659: E/AndroidRuntime(23924): Caused by: java.lang.reflect.InvocationTargetException
06-27 21:28:20.659: E/AndroidRuntime(23924): at java.lang.reflect.Constructor.constructNative(Native Method)
06-27 21:28:20.659: E/AndroidRuntime(23924): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
06-27 21:28:20.659: E/AndroidRuntime(23924): at android.view.LayoutInflater.createView(LayoutInflater.java:586)
06-27 21:28:20.659: E/AndroidRuntime(23924): ... 27 more
06-27 21:28:20.659: E/AndroidRuntime(23924): Caused by: android.content.res.Resources$NotFoundException: File res/drawable/btn_copy.xml from drawable resource ID #0x7f020002
06-27 21:28:20.659: E/AndroidRuntime(23924): at android.content.res.Resources.loadDrawable(Resources.java:1956)
06-27 21:28:20.659: E/AndroidRuntime(23924): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
06-27 21:28:20.659: E/AndroidRuntime(23924): at android.widget.ImageView.<init>(ImageView.java:119)
06-27 21:28:20.659: E/AndroidRuntime(23924): at android.widget.ImageButton.<init>(ImageButton.java:85)
06-27 21:28:20.659: E/AndroidRuntime(23924): at android.widget.ImageButton.<init>(ImageButton.java:81)
06-27 21:28:20.659: E/AndroidRuntime(23924): ... 30 more
06-27 21:28:20.659: E/AndroidRuntime(23924): Caused by: java.lang.NullPointerException
06-27 21:28:20.659: E/AndroidRuntime(23924): at android.graphics.drawable.DrawableContainer$DrawableContainerState.addChild(DrawableContainer.java:515)
06-27 21:28:20.659: E/AndroidRuntime(23924): at android.graphics.drawable.StateListDrawable$StateListState.addStateSet(StateListDrawable.java:278)
06-27 21:28:20.659: E/AndroidRuntime(23924): at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:186)
06-27 21:28:20.659: E/AndroidRuntime(23924): at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:867)
06-27 21:28:20.659: E/AndroidRuntime(23924): at android.graphics.drawable.Drawable.createFromXml(Drawable.java:804)
06-27 21:28:20.659: E/AndroidRuntime(23924): at android.content.res.Resources.loadDrawable(Resources.java:1953)
06-27 21:28:20.659: E/AndroidRuntime(23924): ... 34 more
btn_copy.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/btn_copy_clicked" /> <!-- pressed -->
<item android:drawable="@drawable/btn_copy_normal" /> <!-- default -->
</selector>
btn_copy_clicked and btn_copy_normal exists in ldpi, mdpi, hdpi and xhdpi folders.
Error occurs on the following line:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
And here is the part of XML for the button
<ImageButton
android:id="@+id/button_copy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_below="@+id/edit_to"
android:layout_marginTop="8dp"
android:background="@android:color/transparent"
android:src="@drawable/btn_copy" />
What's wrong?
回答1:
Try moving btn_copy_clicked and btn_copy_normal in plain "drawable" folder
回答2:
requestWindowFeature(Window.FEATURE_NO_TITLE)
is no longer working in Android 3.0 and later versions. You have to use ActionbarSherlock
library for compatibility with versions before 3.0
来源:https://stackoverflow.com/questions/17347293/android-view-inflateexception-binary-xml-file-line-39-error-inflating-class