{"id":2393,"date":"2022-08-30T15:24:29","date_gmt":"2022-08-30T15:24:29","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/01\/05\/force-close-error-every-time-layout-is-changed-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:24:29","modified_gmt":"2022-08-30T15:24:29","slug":"force-close-error-every-time-layout-is-changed-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/force-close-error-every-time-layout-is-changed-collection-of-common-programming-errors\/","title":{"rendered":"Force close error every time layout is changed-Collection of common programming errors"},"content":{"rendered":"<p>My app force closes every time I mess with the Relative Layout&#8217;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.<\/p>\n<p>I&#8217;m using Eclipse.<\/p>\n<p>Why does this happen? Is there a way I can avoid this?<\/p>\n<p><strong>[EDIT]<\/strong><\/p>\n<blockquote>\n<p>07-22 21:39:22.042: D\/dalvikvm(520): GC_EXTERNAL_ALLOC freed 291K, 52% free 2718K\/5639K, external 741K\/1038K, paused 51ms<\/p>\n<p>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)<\/p>\n<p>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<\/p>\n<p>ComponentInfo{com.android.tapme\/com.android.tapme.TapMe}: java.lang.ClassCastException: android.widget.TextView<\/p>\n<p>07-22 21:39:22.443: E\/AndroidRuntime(520): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)<\/p>\n<p>07-22 21:39:22.443: E\/AndroidRuntime(520): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)<\/p>\n<p>07-22 21:39:22.443: E\/AndroidRuntime(520): at android.app.ActivityThread.access$1500(ActivityThread.java:117)<\/p>\n<p>07-22 21:39:22.443: E\/AndroidRuntime(520): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)<\/p>\n<p>07-22 21:39:22.443: E\/AndroidRuntime(520): at android.os.Handler.dispatchMessage(Handler.java:99)<\/p>\n<p>07-22 21:39:22.443: E\/AndroidRuntime(520): at android.os.Looper.loop(Looper.java:123)<\/p>\n<p>07-22 21:39:22.443: E\/AndroidRuntime(520): at android.app.ActivityThread.main(ActivityThread.java:3683)<\/p>\n<p>07-22 21:39:22.443: E\/AndroidRuntime(520): at java.lang.reflect.Method.invokeNative(Native Method)<\/p>\n<p>07-22 21:39:22.443: E\/AndroidRuntime(520): at java.lang.reflect.Method.invoke(Method.java:507)<\/p>\n<p>07-22 21:39:22.443: E\/AndroidRuntime(520): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)<\/p>\n<p>07-22 21:39:22.443: E\/AndroidRuntime(520): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)<\/p>\n<p>07-22 21:39:22.443: E\/AndroidRuntime(520): at dalvik.system.NativeStart.main(Native Method)<\/p>\n<p>07-22 21:39:22.443: E\/AndroidRuntime(520): Caused by: java.lang.ClassCastException: android.widget.TextView<\/p>\n<p>07-22 21:39:22.443: E\/AndroidRuntime(520): at com.android.tapme.TapMe.onCreate(TapMe.java:26)<\/p>\n<p>07-22 21:39:22.443: E\/AndroidRuntime(520): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)<\/p>\n<p>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): &#8230; 11 more<\/p>\n<\/blockquote>\n<p><strong>[EDIT]<\/strong><\/p>\n<p>I edited the layout randomly and finally got it to work. I then added a progress bar and voila! Force close errors again. Here&#8217;s the log.<\/p>\n<blockquote>\n<p>07-26 00:06:57.445: D\/AndroidRuntime(876): Shutting down VM<\/p>\n<p>07-26 00:06:57.465: W\/dalvikvm(876): threadid=1: thread exiting with uncaught exception (group=0x40015560)<\/p>\n<p>07-26 00:06:57.486: E\/AndroidRuntime(876): FATAL EXCEPTION: main<\/p>\n<p>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<\/p>\n<p>07-26 00:06:57.486: E\/AndroidRuntime(876): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)<\/p>\n<p>07-26 00:06:57.486: E\/AndroidRuntime(876): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)<\/p>\n<p>07-26 00:06:57.486: E\/AndroidRuntime(876): at android.app.ActivityThread.access$1500(ActivityThread.java:117)<\/p>\n<p>07-26 00:06:57.486: E\/AndroidRuntime(876): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)<\/p>\n<p>07-26 00:06:57.486: E\/AndroidRuntime(876): at android.os.Handler.dispatchMessage(Handler.java:99)<\/p>\n<p>07-26 00:06:57.486: E\/AndroidRuntime(876): at android.os.Looper.loop(Looper.java:123)<\/p>\n<p>07-26 00:06:57.486: E\/AndroidRuntime(876): at android.app.ActivityThread.main(ActivityThread.java:3683)<\/p>\n<p>07-26 00:06:57.486: E\/AndroidRuntime(876): at java.lang.reflect.Method.invokeNative(Native Method)<\/p>\n<p>07-26 00:06:57.486: E\/AndroidRuntime(876): at java.lang.reflect.Method.invoke(Method.java:507)<\/p>\n<p>07-26 00:06:57.486: E\/AndroidRuntime(876): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)<\/p>\n<p>07-26 00:06:57.486: E\/AndroidRuntime(876): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)<\/p>\n<p>07-26 00:06:57.486: E\/AndroidRuntime(876): at dalvik.system.NativeStart.main(Native Method)<\/p>\n<p>07-26 00:06:57.486: E\/AndroidRuntime(876): Caused by: java.lang.NullPointerException<\/p>\n<p>07-26 00:06:57.486: E\/AndroidRuntime(876): at android.app.Activity.findViewById(Activity.java:1647)<\/p>\n<p>07-26 00:06:57.486: E\/AndroidRuntime(876): at com.android.tapme.TapMe.(TapMe.java:17)<\/p>\n<p>07-26 00:06:57.486: E\/AndroidRuntime(876): at java.lang.Class.newInstanceImpl(Native Method)<\/p>\n<p>07-26 00:06:57.486: E\/AndroidRuntime(876): at java.lang.Class.newInstance(Class.java:1409)<\/p>\n<p>07-26 00:06:57.486: E\/AndroidRuntime(876): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)<\/p>\n<p>07-26 00:06:57.486: E\/AndroidRuntime(876): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)<\/p>\n<p>07-26 00:06:57.486: E\/AndroidRuntime(876): &#8230; 11 more<\/p>\n<\/blockquote>\n<ol>\n<li>\n<p>In a RelativeLayout, all the children elements are placed relative to each other.<\/p>\n<p>Here&#8217;s a code snippet.<\/p>\n<pre><code>android:layout_below=\"@id\/elementOne\"\nandroid:layout_alignParentLeft=\"true\"\nandroid:layout_toLeftOf=\"@+id\/elementTwo\"\n<\/code><\/pre>\n<p>So, mess with one of them, you mess with everything.<\/p>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2014-01-05 22:44:57. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>My app force closes every time I mess with the Relative Layout&#8217;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&#8217;m using Eclipse. Why does this happen? Is there a way I [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2393","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2393","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=2393"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2393\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2393"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2393"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2393"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}