activity_update.xml というレイアウト ファイルがあります。コードは次のとおりです。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/have_class"
android:textAppearance="?android:attr/textAppearanceLarge" />
<RadioGroup
android:id="@+id/rgHaveClass"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/marginLeft"
android:layout_marginRight="@dimen/marginRight"
android:gravity="center"
android:orientation="horizontal" >
<RadioButton
android:id="@+id/rClassNo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/no"
android:textSize="?android:attr/textAppearanceMedium" />
<RadioButton
android:id="@+id/rClassYes"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:checked="true"
android:text="@string/yes"
android:textSize="?android:attr/textAppearanceMedium" />
</RadioGroup>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/paddingTop"
android:text="@string/miss_class"
android:textAppearance="?android:attr/textAppearanceLarge" />
<RadioGroup
android:id="@+id/rgMissClass"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/marginLeft"
android:layout_marginRight="@dimen/marginRight"
android:gravity="center"
android:orientation="horizontal" >
<RadioButton
android:id="@+id/rMissYes"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/yes"
android:textSize="?android:attr/textAppearanceMedium" />
<RadioButton
android:id="@+id/rMissNo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:checked="true"
android:text="@string/no"
android:textSize="?android:attr/textAppearanceMedium" />
</RadioGroup> </LinearLayout>
ActivityUpdate クラスは次のとおりです。
public class ActivityUpdate extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_update);
}}
onCreate() で setContentView(R.layout.activity_update) を使用したところ、Gingerbread と Jellybean の両方で ANR が表示されました。
また、リソース名を別のレイアウト リソースに変更してみましたが、問題なく動作しました。また、Eclipse はエラーや警告を表示せず、コンパイルします。誰かが私のxmlの間違いを指摘してください。本当にありがとう。:)
ところで、logcat出力を取得しました:
*07-14 07:33:53.058: E/AndroidRuntime(1935): FATAL EXCEPTION: main
07-14 07:33:53.058: E/AndroidRuntime(1935): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.wordpress.chillagestudio.attendancemanager/com.wordpress.chillagestudio.attendancemanager.ActivityUpdate}: android.view.InflateException: Binary XML file line #27: Error inflating class android.widget.RadioButton
07-14 07:33:53.058: E/AndroidRuntime(1935): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
07-14 07:33:53.058: E/AndroidRuntime(1935): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
07-14 07:33:53.058: E/AndroidRuntime(1935): at android.app.ActivityThread.access$600(ActivityThread.java:141)
07-14 07:33:53.058: E/AndroidRuntime(1935): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
07-14 07:33:53.058: E/AndroidRuntime(1935): at android.os.Handler.dispatchMessage(Handler.java:99)
07-14 07:33:53.058: E/AndroidRuntime(1935): at android.os.Looper.loop(Looper.java:137)
07-14 07:33:53.058: E/AndroidRuntime(1935): at android.app.ActivityThread.main(ActivityThread.java:5039)
07-14 07:33:53.058: E/AndroidRuntime(1935): at java.lang.reflect.Method.invokeNative(Native Method)
07-14 07:33:53.058: E/AndroidRuntime(1935): at java.lang.reflect.Method.invoke(Method.java:511)
07-14 07:33:53.058: E/AndroidRuntime(1935): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
07-14 07:33:53.058: E/AndroidRuntime(1935): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
07-14 07:33:53.058: E/AndroidRuntime(1935): at dalvik.system.NativeStart.main(Native Method)
07-14 07:33:53.058: E/AndroidRuntime(1935): Caused by: android.view.InflateException: Binary XML file line #27: Error inflating class android.widget.RadioButton
07-14 07:33:53.058: E/AndroidRuntime(1935): at android.view.LayoutInflater.createView(LayoutInflater.java:613)
07-14 07:33:53.058: E/AndroidRuntime(1935): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
07-14 07:33:53.058: E/AndroidRuntime(1935): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
07-14 07:33:53.058: E/AndroidRuntime(1935): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
07-14 07:33:53.058: E/AndroidRuntime(1935): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
07-14 07:33:53.058: E/AndroidRuntime(1935): at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
07-14 07:33:53.058: E/AndroidRuntime(1935): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
07-14 07:33:53.058: E/AndroidRuntime(1935): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
07-14 07:33:53.058: E/AndroidRuntime(1935): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
07-14 07:33:53.058: E/AndroidRuntime(1935): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
07-14 07:33:53.058: E/AndroidRuntime(1935): at android.app.Activity.setContentView(Activity.java:1881)
07-14 07:33:53.058: E/AndroidRuntime(1935): at com.wordpress.chillagestudio.attendancemanager.ActivityUpdate.onCreate(ActivityUpdate.java:12)
07-14 07:33:53.058: E/AndroidRuntime(1935): at android.app.Activity.performCreate(Activity.java:5104)
07-14 07:33:53.058: E/AndroidRuntime(1935): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
07-14 07:33:53.058: E/AndroidRuntime(1935): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
07-14 07:33:53.058: E/AndroidRuntime(1935): ... 11 more
07-14 07:33:53.058: E/AndroidRuntime(1935): Caused by: java.lang.reflect.InvocationTargetException
07-14 07:33:53.058: E/AndroidRuntime(1935): at java.lang.reflect.Constructor.constructNative(Native Method)
07-14 07:33:53.058: E/AndroidRuntime(1935): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
07-14 07:33:53.058: E/AndroidRuntime(1935): at android.view.LayoutInflater.createView(LayoutInflater.java:587)
07-14 07:33:53.058: E/AndroidRuntime(1935): ... 25 more
07-14 07:33:53.058: E/AndroidRuntime(1935): Caused by: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x1
07-14 07:33:53.058: E/AndroidRuntime(1935): at android.content.res.TypedArray.getDimensionPixelSize(TypedArray.java:463)
07-14 07:33:53.058: E/AndroidRuntime(1935): at android.widget.TextView.<init>(TextView.java:787)
07-14 07:33:53.058: E/AndroidRuntime(1935): at android.widget.Button.<init>(Button.java:107)
07-14 07:33:53.058: E/AndroidRuntime(1935): at android.widget.CompoundButton.<init>(CompoundButton.java:68)
07-14 07:33:53.058: E/AndroidRuntime(1935): at android.widget.RadioButton.<init>(RadioButton.java:63)
07-14 07:33:53.058: E/AndroidRuntime(1935): at android.widget.RadioButton.<init>(RadioButton.java:59)
07-14 07:33:53.058: E/AndroidRuntime(1935): ... 28 more*