0

我正面临给定的问题。

在 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" />

怎么了?

4

2 回答 2

2

尝试在普通的“drawable”文件夹中移动 btn_copy_clicked 和 btn_copy_normal

于 2013-07-04T10:46:17.247 回答
0
requestWindowFeature(Window.FEATURE_NO_TITLE) 

不再适用于Android 3.0及更高版本。您必须使用ActionbarSherlock库与 3.0 之前的版本兼容

于 2013-07-06T13:22:59.627 回答