XML Relative Layout order change Crashes Program (Android)-Collection of common programming errors

I want to move an ImageView to the top of my layout so that it will be behind the other objects. When I do, it crashes. This works and the program compiles and runs:



    

    

    

    

    

    

    

    

    


But when I move my ImageView to the top of the layout, the program crashes and I cannot figure out why! Here is the minor change which crashes the program along with the LogCat:



    

    

    

    

    

    

    

    

    


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

Thanks!

  1. There was a casting error. Not sure why that caused the problem, but that was the fix.

  2. I got the same thing when using Android Annotations (http://androidannotations.org/). A project->clean fixed it, so I think EJK’s guess about something referencing elements by index is correct.