2

ImageViewをレイアウトの一番上に移動して、他のオブジェクトの後ろに配置したいと思います。私がそうすると、それはクラッシュします。これは機能し、プログラムはコンパイルして実行します。

<RelativeLayout 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"
    tools:context=".Nim" >

    <TextView
        android:id="@+id/tvTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:text="@string/tvTitle"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <TextView
        android:id="@+id/tvInfo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/tvTitle"
        android:layout_centerHorizontal="true"
        android:text="@string/tvInfo"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <SeekBar
        android:id="@+id/sbMarbles"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignRight="@+id/tvInfo" />

    <Button
        android:id="@+id/butMarbles"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:text="@string/butMarbles" />

    <EditText
        android:id="@+id/tvMarbles"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_toLeftOf="@+id/butMarbles"
        android:layout_toRightOf="@+id/sbMarbles"
        android:ems="10"
        android:inputType="number" />

    <TextView
        android:id="@+id/tvInfo2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/tvInfo"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="43dp"
        android:text="@string/tvInfo"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <Button
        android:id="@+id/butYes"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/tvInfo2"
        android:layout_marginTop="83dp"
        android:layout_toLeftOf="@+id/tvTitle"
        android:text="@string/butYes" />

    <Button
        android:id="@+id/butNo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/butYes"
        android:layout_alignBottom="@+id/butYes"
        android:layout_toRightOf="@+id/tvInfo2"
        android:text="@string/butNo" />

    <ImageView
        android:id="@+id/bg"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:src="@drawable/marbles" />

</RelativeLayout>

しかし、ImageViewをレイアウトの一番上に移動すると、プログラムがクラッシュし、理由がわかりません。LogCatとともにプログラムをクラッシュさせるマイナーな変更は次のとおりです。

<RelativeLayout 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"
    tools:context=".Nim" >

    <ImageView
        android:id="@+id/bg"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:src="@drawable/marbles" />

    <TextView
        android:id="@+id/tvTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:text="@string/tvTitle"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <TextView
        android:id="@+id/tvInfo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/tvTitle"
        android:layout_centerHorizontal="true"
        android:text="@string/tvInfo"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <SeekBar
        android:id="@+id/sbMarbles"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignRight="@+id/tvInfo" />

    <Button
        android:id="@+id/butMarbles"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:text="@string/butMarbles" />

    <EditText
        android:id="@+id/tvMarbles"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_toLeftOf="@+id/butMarbles"
        android:layout_toRightOf="@+id/sbMarbles"
        android:ems="10"
        android:inputType="number" />

    <TextView
        android:id="@+id/tvInfo2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/tvInfo"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="43dp"
        android:text="@string/tvInfo"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <Button
        android:id="@+id/butYes"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/tvInfo2"
        android:layout_marginTop="83dp"
        android:layout_toLeftOf="@+id/tvTitle"
        android:text="@string/butYes" />

    <Button
        android:id="@+id/butNo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/butYes"
        android:layout_alignBottom="@+id/butYes"
        android:layout_toRightOf="@+id/tvInfo2"
        android:text="@string/butNo" />

</RelativeLayout>

01-07 21:00:00.453: E/AndroidRuntime(568): FATAL EXCEPTION: main
01-07 21:00:00.453: E/AndroidRuntime(568): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.evorlor.gameofnim/com.evorlor.gameofnim.Nim}: java.lang.ClassCastException: android.widget.TextView
01-07 21:00:00.453: E/AndroidRuntime(568):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
01-07 21:00:00.453: E/AndroidRuntime(568):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
01-07 21:00:00.453: E/AndroidRuntime(568):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
01-07 21:00:00.453: E/AndroidRuntime(568):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
01-07 21:00:00.453: E/AndroidRuntime(568):  at android.os.Handler.dispatchMessage(Handler.java:99)
01-07 21:00:00.453: E/AndroidRuntime(568):  at android.os.Looper.loop(Looper.java:123)
01-07 21:00:00.453: E/AndroidRuntime(568):  at android.app.ActivityThread.main(ActivityThread.java:3683)
01-07 21:00:00.453: E/AndroidRuntime(568):  at java.lang.reflect.Method.invokeNative(Native Method)
01-07 21:00:00.453: E/AndroidRuntime(568):  at java.lang.reflect.Method.invoke(Method.java:507)
01-07 21:00:00.453: E/AndroidRuntime(568):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
01-07 21:00:00.453: E/AndroidRuntime(568):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-07 21:00:00.453: E/AndroidRuntime(568):  at dalvik.system.NativeStart.main(Native Method)
01-07 21:00:00.453: E/AndroidRuntime(568): Caused by: java.lang.ClassCastException: android.widget.TextView
01-07 21:00:00.453: E/AndroidRuntime(568):  at com.evorlor.gameofnim.Nim.listener(Nim.java:56)
01-07 21:00:00.453: E/AndroidRuntime(568):  at com.evorlor.gameofnim.Nim.onCreate(Nim.java:41)
01-07 21:00:00.453: E/AndroidRuntime(568):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-07 21:00:00.453: E/AndroidRuntime(568):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
01-07 21:00:00.453: E/AndroidRuntime(568):  ... 11 more
01-07 21:18:20.403: E/AndroidRuntime(704): FATAL EXCEPTION: main
01-07 21:18:20.403: E/AndroidRuntime(704): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.evorlor.gameofnim/com.evorlor.gameofnim.Opening}: java.lang.NullPointerException
01-07 21:18:20.403: E/AndroidRuntime(704):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
01-07 21:18:20.403: E/AndroidRuntime(704):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
01-07 21:18:20.403: E/AndroidRuntime(704):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
01-07 21:18:20.403: E/AndroidRuntime(704):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
01-07 21:18:20.403: E/AndroidRuntime(704):  at android.os.Handler.dispatchMessage(Handler.java:99)
01-07 21:18:20.403: E/AndroidRuntime(704):  at android.os.Looper.loop(Looper.java:123)
01-07 21:18:20.403: E/AndroidRuntime(704):  at android.app.ActivityThread.main(ActivityThread.java:3683)
01-07 21:18:20.403: E/AndroidRuntime(704):  at java.lang.reflect.Method.invokeNative(Native Method)
01-07 21:18:20.403: E/AndroidRuntime(704):  at java.lang.reflect.Method.invoke(Method.java:507)
01-07 21:18:20.403: E/AndroidRuntime(704):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
01-07 21:18:20.403: E/AndroidRuntime(704):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-07 21:18:20.403: E/AndroidRuntime(704):  at dalvik.system.NativeStart.main(Native Method)
01-07 21:18:20.403: E/AndroidRuntime(704): Caused by: java.lang.NullPointerException
01-07 21:18:20.403: E/AndroidRuntime(704):  at com.evorlor.gameofnim.Opening.listener(Opening.java:36)
01-07 21:18:20.403: E/AndroidRuntime(704):  at com.evorlor.gameofnim.Opening.onCreate(Opening.java:28)
01-07 21:18:20.403: E/AndroidRuntime(704):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-07 21:18:20.403: E/AndroidRuntime(704):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
01-07 21:18:20.403: E/AndroidRuntime(704):  ... 11 more
01-07 21:19:32.743: E/AndroidRuntime(737): FATAL EXCEPTION: main
01-07 21:19:32.743: E/AndroidRuntime(737): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.evorlor.gameofnim/com.evorlor.gameofnim.Opening}: java.lang.NullPointerException
01-07 21:19:32.743: E/AndroidRuntime(737):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
01-07 21:19:32.743: E/AndroidRuntime(737):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
01-07 21:19:32.743: E/AndroidRuntime(737):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
01-07 21:19:32.743: E/AndroidRuntime(737):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
01-07 21:19:32.743: E/AndroidRuntime(737):  at android.os.Handler.dispatchMessage(Handler.java:99)
01-07 21:19:32.743: E/AndroidRuntime(737):  at android.os.Looper.loop(Looper.java:123)
01-07 21:19:32.743: E/AndroidRuntime(737):  at android.app.ActivityThread.main(ActivityThread.java:3683)
01-07 21:19:32.743: E/AndroidRuntime(737):  at java.lang.reflect.Method.invokeNative(Native Method)
01-07 21:19:32.743: E/AndroidRuntime(737):  at java.lang.reflect.Method.invoke(Method.java:507)
01-07 21:19:32.743: E/AndroidRuntime(737):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
01-07 21:19:32.743: E/AndroidRuntime(737):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-07 21:19:32.743: E/AndroidRuntime(737):  at dalvik.system.NativeStart.main(Native Method)
01-07 21:19:32.743: E/AndroidRuntime(737): Caused by: java.lang.NullPointerException
01-07 21:19:32.743: E/AndroidRuntime(737):  at com.evorlor.gameofnim.Opening.listener(Opening.java:36)
01-07 21:19:32.743: E/AndroidRuntime(737):  at com.evorlor.gameofnim.Opening.onCreate(Opening.java:28)
01-07 21:19:32.743: E/AndroidRuntime(737):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-07 21:19:32.743: E/AndroidRuntime(737):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
01-07 21:19:32.743: E/AndroidRuntime(737):  ... 11 more
01-07 21:23:52.323: E/AndroidRuntime(747): FATAL EXCEPTION: main
01-07 21:23:52.323: E/AndroidRuntime(747): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.evorlor.gameofnim/com.evorlor.gameofnim.Opening}: java.lang.NullPointerException
01-07 21:23:52.323: E/AndroidRuntime(747):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
01-07 21:23:52.323: E/AndroidRuntime(747):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
01-07 21:23:52.323: E/AndroidRuntime(747):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
01-07 21:23:52.323: E/AndroidRuntime(747):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
01-07 21:23:52.323: E/AndroidRuntime(747):  at android.os.Handler.dispatchMessage(Handler.java:99)
01-07 21:23:52.323: E/AndroidRuntime(747):  at android.os.Looper.loop(Looper.java:123)
01-07 21:23:52.323: E/AndroidRuntime(747):  at android.app.ActivityThread.main(ActivityThread.java:3683)
01-07 21:23:52.323: E/AndroidRuntime(747):  at java.lang.reflect.Method.invokeNative(Native Method)
01-07 21:23:52.323: E/AndroidRuntime(747):  at java.lang.reflect.Method.invoke(Method.java:507)
01-07 21:23:52.323: E/AndroidRuntime(747):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
01-07 21:23:52.323: E/AndroidRuntime(747):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-07 21:23:52.323: E/AndroidRuntime(747):  at dalvik.system.NativeStart.main(Native Method)
01-07 21:23:52.323: E/AndroidRuntime(747): Caused by: java.lang.NullPointerException
01-07 21:23:52.323: E/AndroidRuntime(747):  at com.evorlor.gameofnim.Opening.listener(Opening.java:36)
01-07 21:23:52.323: E/AndroidRuntime(747):  at com.evorlor.gameofnim.Opening.onCreate(Opening.java:28)
01-07 21:23:52.323: E/AndroidRuntime(747):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-07 21:23:52.323: E/AndroidRuntime(747):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
01-07 21:23:52.323: E/AndroidRuntime(747):  ... 11 more
01-07 21:33:28.122: E/AndroidRuntime(813): FATAL EXCEPTION: main
01-07 21:33:28.122: E/AndroidRuntime(813): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.evorlor.gameofnim/com.evorlor.gameofnim.Opening}: java.lang.NullPointerException
01-07 21:33:28.122: E/AndroidRuntime(813):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
01-07 21:33:28.122: E/AndroidRuntime(813):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
01-07 21:33:28.122: E/AndroidRuntime(813):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
01-07 21:33:28.122: E/AndroidRuntime(813):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
01-07 21:33:28.122: E/AndroidRuntime(813):  at android.os.Handler.dispatchMessage(Handler.java:99)
01-07 21:33:28.122: E/AndroidRuntime(813):  at android.os.Looper.loop(Looper.java:123)
01-07 21:33:28.122: E/AndroidRuntime(813):  at android.app.ActivityThread.main(ActivityThread.java:3683)
01-07 21:33:28.122: E/AndroidRuntime(813):  at java.lang.reflect.Method.invokeNative(Native Method)
01-07 21:33:28.122: E/AndroidRuntime(813):  at java.lang.reflect.Method.invoke(Method.java:507)
01-07 21:33:28.122: E/AndroidRuntime(813):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
01-07 21:33:28.122: E/AndroidRuntime(813):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-07 21:33:28.122: E/AndroidRuntime(813):  at dalvik.system.NativeStart.main(Native Method)
01-07 21:33:28.122: E/AndroidRuntime(813): Caused by: java.lang.NullPointerException
01-07 21:33:28.122: E/AndroidRuntime(813):  at com.evorlor.gameofnim.Opening.listener(Opening.java:36)
01-07 21:33:28.122: E/AndroidRuntime(813):  at com.evorlor.gameofnim.Opening.onCreate(Opening.java:28)
01-07 21:33:28.122: E/AndroidRuntime(813):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-07 21:33:28.122: E/AndroidRuntime(813):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
01-07 21:33:28.122: E/AndroidRuntime(813):  ... 11 more

ありがとう!

4

2 に答える 2

1

Android Annotations(http://androidannotations.org/)を使用しても同じことがわかりました。プロジェクト->クリーンで修正されたので、インデックスによって要素を参照しているものについてのEJKの推測は正しいと思います。

于 2013-01-29T11:22:31.143 に答える
0

キャストエラーがありました。それが問題を引き起こした理由はわかりませんが、それが修正されました。

于 2013-01-08T04:31:30.707 に答える