Force close error every time layout is changed-Collection of common programming errors
My app force closes every time I mess with the Relative Layout’s positioning now and then. I have to arbitrarily keep re-positioning them for the app to work again. Or position them all at the topmost left corner and then re arrange them.
I’m using Eclipse.
Why does this happen? Is there a way I can avoid this?
[EDIT]
07-22 21:39:22.042: D/dalvikvm(520): GC_EXTERNAL_ALLOC freed 291K, 52% free 2718K/5639K, external 741K/1038K, paused 51ms
07-22 21:39:22.422: D/AndroidRuntime(520): Shutting down VM 07-22 21:39:22.432: W/dalvikvm(520): threadid=1: thread exiting with uncaught exception (group=0x40015560)
07-22 21:39:22.443: E/AndroidRuntime(520): FATAL EXCEPTION: main 07-22 21:39:22.443: E/AndroidRuntime(520): java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.android.tapme/com.android.tapme.TapMe}: java.lang.ClassCastException: android.widget.TextView
07-22 21:39:22.443: E/AndroidRuntime(520): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
07-22 21:39:22.443: E/AndroidRuntime(520): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
07-22 21:39:22.443: E/AndroidRuntime(520): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
07-22 21:39:22.443: E/AndroidRuntime(520): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
07-22 21:39:22.443: E/AndroidRuntime(520): at android.os.Handler.dispatchMessage(Handler.java:99)
07-22 21:39:22.443: E/AndroidRuntime(520): at android.os.Looper.loop(Looper.java:123)
07-22 21:39:22.443: E/AndroidRuntime(520): at android.app.ActivityThread.main(ActivityThread.java:3683)
07-22 21:39:22.443: E/AndroidRuntime(520): at java.lang.reflect.Method.invokeNative(Native Method)
07-22 21:39:22.443: E/AndroidRuntime(520): at java.lang.reflect.Method.invoke(Method.java:507)
07-22 21:39:22.443: E/AndroidRuntime(520): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
07-22 21:39:22.443: E/AndroidRuntime(520): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
07-22 21:39:22.443: E/AndroidRuntime(520): at dalvik.system.NativeStart.main(Native Method)
07-22 21:39:22.443: E/AndroidRuntime(520): Caused by: java.lang.ClassCastException: android.widget.TextView
07-22 21:39:22.443: E/AndroidRuntime(520): at com.android.tapme.TapMe.onCreate(TapMe.java:26)
07-22 21:39:22.443: E/AndroidRuntime(520): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-22 21:39:22.443: E/AndroidRuntime(520): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611) 07-22 21:39:22.443: E/AndroidRuntime(520): … 11 more
[EDIT]
I edited the layout randomly and finally got it to work. I then added a progress bar and voila! Force close errors again. Here’s the log.
07-26 00:06:57.445: D/AndroidRuntime(876): Shutting down VM
07-26 00:06:57.465: W/dalvikvm(876): threadid=1: thread exiting with uncaught exception (group=0x40015560)
07-26 00:06:57.486: E/AndroidRuntime(876): FATAL EXCEPTION: main
07-26 00:06:57.486: E/AndroidRuntime(876): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.android.tapme/com.android.tapme.TapMe}: java.lang.NullPointerException
07-26 00:06:57.486: E/AndroidRuntime(876): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
07-26 00:06:57.486: E/AndroidRuntime(876): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
07-26 00:06:57.486: E/AndroidRuntime(876): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
07-26 00:06:57.486: E/AndroidRuntime(876): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
07-26 00:06:57.486: E/AndroidRuntime(876): at android.os.Handler.dispatchMessage(Handler.java:99)
07-26 00:06:57.486: E/AndroidRuntime(876): at android.os.Looper.loop(Looper.java:123)
07-26 00:06:57.486: E/AndroidRuntime(876): at android.app.ActivityThread.main(ActivityThread.java:3683)
07-26 00:06:57.486: E/AndroidRuntime(876): at java.lang.reflect.Method.invokeNative(Native Method)
07-26 00:06:57.486: E/AndroidRuntime(876): at java.lang.reflect.Method.invoke(Method.java:507)
07-26 00:06:57.486: E/AndroidRuntime(876): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
07-26 00:06:57.486: E/AndroidRuntime(876): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
07-26 00:06:57.486: E/AndroidRuntime(876): at dalvik.system.NativeStart.main(Native Method)
07-26 00:06:57.486: E/AndroidRuntime(876): Caused by: java.lang.NullPointerException
07-26 00:06:57.486: E/AndroidRuntime(876): at android.app.Activity.findViewById(Activity.java:1647)
07-26 00:06:57.486: E/AndroidRuntime(876): at com.android.tapme.TapMe.(TapMe.java:17)
07-26 00:06:57.486: E/AndroidRuntime(876): at java.lang.Class.newInstanceImpl(Native Method)
07-26 00:06:57.486: E/AndroidRuntime(876): at java.lang.Class.newInstance(Class.java:1409)
07-26 00:06:57.486: E/AndroidRuntime(876): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
07-26 00:06:57.486: E/AndroidRuntime(876): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
07-26 00:06:57.486: E/AndroidRuntime(876): … 11 more
-
In a RelativeLayout, all the children elements are placed relative to each other.
Here’s a code snippet.
android:layout_below="@id/elementOne" android:layout_alignParentLeft="true" android:layout_toLeftOf="@+id/elementTwo"
So, mess with one of them, you mess with everything.