Android 4.0 でアプリを実行していますが、問題なく動作します。ただし、Android 2.3.4 を実行している電話でテストしたところ、アプリがクラッシュしました。Imagebutton ビューを設定しようとすると、例外がスローされます。
03-07 17:21:58.789: E/AndroidRuntime(5741): FATAL EXCEPTION: main
03-07 17:21:58.789: E/AndroidRuntime(5741): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.motesclient/com.example.motesclient.ConnectActivity}: android.view.InflateException: Binary XML file line #22: Error inflating class android.widget.ImageButton
03-07 17:21:58.789: E/AndroidRuntime(5741): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
03-07 17:21:58.789: E/AndroidRuntime(5741): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
03-07 17:21:58.789: E/AndroidRuntime(5741): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
03-07 17:21:58.789: E/AndroidRuntime(5741): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
03-07 17:21:58.789: E/AndroidRuntime(5741): at android.os.Handler.dispatchMessage(Handler.java:99)
03-07 17:21:58.789: E/AndroidRuntime(5741): at android.os.Looper.loop(Looper.java:130)
03-07 17:21:58.789: E/AndroidRuntime(5741): at android.app.ActivityThread.main(ActivityThread.java:3687)
03-07 17:21:58.789: E/AndroidRuntime(5741): at java.lang.reflect.Method.invokeNative(Native Method)
03-07 17:21:58.789: E/AndroidRuntime(5741): at java.lang.reflect.Method.invoke(Method.java:507)
03-07 17:21:58.789: E/AndroidRuntime(5741): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
03-07 17:21:58.789: E/AndroidRuntime(5741): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
03-07 17:21:58.789: E/AndroidRuntime(5741): at dalvik.system.NativeStart.main(Native Method)
03-07 17:21:58.789: E/AndroidRuntime(5741): Caused by: android.view.InflateException: Binary XML file line #22: Error inflating class android.widget.ImageButton
03-07 17:21:58.789: E/AndroidRuntime(5741): at android.view.LayoutInflater.createView(LayoutInflater.java:518)
03-07 17:21:58.789: E/AndroidRuntime(5741): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
03-07 17:21:58.789: E/AndroidRuntime(5741): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
03-07 17:21:58.789: E/AndroidRuntime(5741): at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
03-07 17:21:58.789: E/AndroidRuntime(5741): at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
03-07 17:21:58.789: E/AndroidRuntime(5741): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
03-07 17:21:58.789: E/AndroidRuntime(5741): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
03-07 17:21:58.789: E/AndroidRuntime(5741): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:209)
03-07 17:21:58.789: E/AndroidRuntime(5741): at android.app.Activity.setContentView(Activity.java:1657)
03-07 17:21:58.789: E/AndroidRuntime(5741): at com.example.motesclient.ConnectActivity.onCreate(ConnectActivity.java:27)
03-07 17:21:58.789: E/AndroidRuntime(5741): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-07 17:21:58.789: E/AndroidRuntime(5741): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
03-07 17:21:58.789: E/AndroidRuntime(5741): ... 11 more
03-07 17:21:58.789: E/AndroidRuntime(5741): Caused by: java.lang.reflect.InvocationTargetException
03-07 17:21:58.789: E/AndroidRuntime(5741): at java.lang.reflect.Constructor.constructNative(Native Method)
03-07 17:21:58.789: E/AndroidRuntime(5741): at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
03-07 17:21:58.789: E/AndroidRuntime(5741): at android.view.LayoutInflater.createView(LayoutInflater.java:505)
03-07 17:21:58.789: E/AndroidRuntime(5741): ... 22 more
03-07 17:21:58.789: E/AndroidRuntime(5741): Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x2/d=0x101030e a=-1}
03-07 17:21:58.789: E/AndroidRuntime(5741): at android.content.res.Resources.loadDrawable(Resources.java:1681)
03-07 17:21:58.789: E/AndroidRuntime(5741): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
03-07 17:21:58.789: E/AndroidRuntime(5741): at android.view.View.<init>(View.java:1961)
03-07 17:21:58.789: E/AndroidRuntime(5741): at android.widget.ImageView.<init>(ImageView.java:112)
03-07 17:21:58.789: E/AndroidRuntime(5741): at android.widget.ImageButton.<init>(ImageButton.java:85)
03-07 17:21:58.789: E/AndroidRuntime(5741): at android.widget.ImageButton.<init>(ImageButton.java:81)
03-07 17:21:58.789: E/AndroidRuntime(5741): ... 25 more
これはイメージボタンです:
<ImageButton
android:id="@+id/connect_button"
android:background="?android:attr/selectableItemBackground"
android:contentDescription="@string/connect_picture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/connectxml"/>
これが connectxml.xml ファイルで、drawable フォルダーに配置されています。
<?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/connectbuttonpressed" /> <!-- pressed -->
<item android:state_focused="true"
android:drawable="@drawable/connectbuttonpressed" /> <!-- focused -->
<item android:drawable="@drawable/connectbutton" /> <!-- default -->
</selector>
それを修正する方法について何か考えはありますか?