我正面临着问题。
在Galaxy s2上一切正常,在noname android 2.3(手机和7'平板电脑)上 - 每件事都可以。 但是galaxy tab2和note2给出了这个错误。
这是堆栈跟踪:
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和btn_copy_normal存在于ldpi,mdpi,hdpi和xhdpi文件夹中。
以下行发生错误:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
这是按钮
的XML部分<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" />
怎么了?
答案 0 :(得分:2)
尝试在普通的“drawable”文件夹中移动btn_copy_clicked和btn_copy_normal
答案 1 :(得分:0)
requestWindowFeature(Window.FEATURE_NO_TITLE)
已不再使用 Android 3.0 及更高版本。您必须使用ActionbarSherlock
库来与3.0之前的版本兼容