{"id":2317,"date":"2022-08-30T15:23:51","date_gmt":"2022-08-30T15:23:51","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/01\/05\/relativelayout-layout_above-crashing-app-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:23:51","modified_gmt":"2022-08-30T15:23:51","slug":"relativelayout-layout_above-crashing-app-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/relativelayout-layout_above-crashing-app-collection-of-common-programming-errors\/","title":{"rendered":"RelativeLayout layout_above crashing app-Collection of common programming errors"},"content":{"rendered":"<p>&#8211;UPDATE&#8211; April 17th, 2012<\/p>\n<p>It seems that it is only crashing when I add:<\/p>\n<pre><code>        android:layout_above=\"@+id\/lakeSearchAdWebView\"\n<\/code><\/pre>\n<p>to lakeSearchScrollView, adding it to just lakeSearchDetailsWebView works fine.<\/p>\n<p>Here&#8217;s my layout:<\/p>\n<pre><code>\n\n\n\n\n    \n\n        \n\n        \n\n            \n        \n\n        \n\n        \n        \n    \n\n\n\n\n\n\n\n<\/code><\/pre>\n<p>I want to have lakeSearchScrollView and lakeSearchDetailsWebView setup so that they are always above lakeSearchAdWebview, so lakeSearchAdWebview is always visible. Only ONE of lakeSearchScrollView and lakeSearchDetailsWebView is visible at a time, that&#8217;s whey they&#8217;re setup to be sitting on top of eachother.<\/p>\n<p>If I add the following line to lakeSearchScrollView, the apps crashes:<\/p>\n<pre><code>android:layout_above=\"@+id\/lakeSearchAdWebView\"\n<\/code><\/pre>\n<p>Can anyone tell me what I&#8217;m doing wrong? I&#8217;m still quite new to Android so I&#8217;m thinking it&#8217;s probably a newbie mistake&#8230; thanks in advance!<\/p>\n<p>&#8211;UPDATE&#8211; Source Code:<\/p>\n<pre><code>package com.theappdoor.ifish;\n\nimport java.util.ArrayList;\nimport java.util.Iterator;\nimport java.util.List;\n\nimport android.app.Activity;\nimport android.app.AlertDialog;\nimport android.app.TabActivity;\nimport android.content.Context;\nimport android.content.DialogInterface;\nimport android.content.Intent;\nimport android.content.SharedPreferences;\nimport android.os.Bundle;\nimport android.view.LayoutInflater;\nimport android.view.View;\nimport android.view.View.OnClickListener;\nimport android.view.inputmethod.InputMethodManager;\nimport android.webkit.WebSettings;\nimport android.webkit.WebView;\nimport android.webkit.WebViewClient;\nimport android.widget.Button;\nimport android.widget.EditText;\nimport android.widget.ScrollView;\nimport android.widget.TabHost;\nimport android.widget.TableLayout;\nimport android.widget.TableRow;\nimport android.widget.TextView;\n\nimport android.util.Log;\n\npublic class iFishLakeSearch extends Activity {\n\n    private EditText searchBar;\n    private TableLayout resultsTableLayout;\n    private DataHelper dh;\n    private iFishLakeDetails iFishLD;\n\n    private Button lakeSearchBTN;\n    private ScrollView searchScrollView;\n    private WebView detailsWebView;\n    private String lake_id;\n\n    private WebView lakeSearchAdWebView;\n\n    public void onCreate(Bundle savedInstanceState) {\n        super.onCreate(savedInstanceState);\n\n        \/\/setContentView(R.layout.lakesearch);\n        \/\/This sets the context to the be of the parent, which is what we want\n        View viewToLoad = LayoutInflater.from(this.getParent()).inflate(R.layout.lakesearch, null);\n        setContentView(viewToLoad);\n\n        \/\/setup vars\n\n        this.dh = new DataHelper(this);\n        this.iFishLD = new iFishLakeDetails(this);\n\n        \/\/ connect our elements from the UI XML\n\n        this.searchBar = (EditText) findViewById(R.id.searchBar); \/\/LINE 61\n\n        this.resultsTableLayout = (TableLayout) findViewById(R.id.resultsTableLayout);\n\n        this.lakeSearchBTN = (Button) findViewById(R.id.lakeSearchSearchBTN);\n        this.lakeSearchBTN.setOnClickListener(new OnClickListener(){\n            public void onClick(View v) {\n                lakeSearch(v);\n            }\n        });\n\n\n        this.searchScrollView = (ScrollView) findViewById(R.id.lakeSearchScrollView);\n\n        this.detailsWebView = (WebView) findViewById(R.id.lakeSearchDetailsWebView);\n        WebSettings webSettings = this.detailsWebView.getSettings();\n        webSettings.setJavaScriptEnabled(true);\n        this.detailsWebView.setWebViewClient(new MyWebViewClient());\n        this.detailsWebView.addJavascriptInterface(new JavaScriptInterface(this), \"Android\");\n\n        this.detailsWebView.loadUrl(\"file:\/\/\/android_asset\/webassets\/index.html\");\n\n        this.lakeSearchAdWebView = (WebView)findViewById(R.id.lakeSearchAdWebView);\n        webSettings = this.lakeSearchAdWebView.getSettings();\n        webSettings.setJavaScriptEnabled(true);\n\n        this.lakeSearchAdWebView.loadUrl(this.getString(R.string.server)+\"\/iFish_ads\/\");\n\n    }\n<\/code><\/pre>\n<p>Line 61:<\/p>\n<pre><code>this.searchBar = (EditText) findViewById(R.id.searchBar);\n<\/code><\/pre>\n<p>&#8211;UPDATE&#8211;<\/p>\n<p>Crash Log:<\/p>\n<pre><code>    04-16 13:22:23.951: D\/AndroidRuntime(20896): Shutting down VM\n    04-16 13:22:23.951: W\/dalvikvm(20896): threadid=1: thread exiting with uncaught exception (group=0x40015578)\n    04-16 13:22:23.970: E\/AndroidRuntime(20896): FATAL EXCEPTION: main\n    04-16 13:22:23.970: E\/AndroidRuntime(20896): java.lang.IllegalStateException: Could not execute method of the activity\n    04-16 13:22:23.970: E\/AndroidRuntime(20896):    at android.view.View$1.onClick(View.java:2154)\n    04-16 13:22:23.970: E\/AndroidRuntime(20896):    at android.view.View.performClick(View.java:2538)\n    04-16 13:22:23.970: E\/AndroidRuntime(20896):    at android.view.View$PerformClick.run(View.java:9152)\n    04-16 13:22:23.970: E\/AndroidRuntime(20896):    at android.os.Handler.handleCallback(Handler.java:587)\n    04-16 13:22:23.970: E\/AndroidRuntime(20896):    at android.os.Handler.dispatchMessage(Handler.java:92)\n    04-16 13:22:23.970: E\/AndroidRuntime(20896):    at android.os.Looper.loop(Looper.java:123)\n    04-16 13:22:23.970: E\/AndroidRuntime(20896):    at android.app.ActivityThread.main(ActivityThread.java:3687)\n    04-16 13:22:23.970: E\/AndroidRuntime(20896):    at java.lang.reflect.Method.invokeNative(Native Method)\n    04-16 13:22:23.970: E\/AndroidRuntime(20896):    at java.lang.reflect.Method.invoke(Method.java:507)\n    04-16 13:22:23.970: E\/AndroidRuntime(20896):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)\n    04-16 13:22:23.970: E\/AndroidRuntime(20896):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)\n    04-16 13:22:23.970: E\/AndroidRuntime(20896):    at dalvik.system.NativeStart.main(Native Method)\n    04-16 13:22:23.970: E\/AndroidRuntime(20896): Caused by: java.lang.reflect.InvocationTargetException\n    04-16 13:22:23.970: E\/AndroidRuntime(20896):    at java.lang.reflect.Method.invokeNative(Native Method)\n    04-16 13:22:23.970: E\/AndroidRuntime(20896):    at java.lang.reflect.Method.invoke(Method.java:507)\n    04-16 13:22:23.970: E\/AndroidRuntime(20896):    at android.view.View$1.onClick(View.java:2149)\n    04-16 13:22:23.970: E\/AndroidRuntime(20896):    ... 11 more\n    04-16 13:22:23.970: E\/AndroidRuntime(20896): Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.theappdoor.ifish\/com.theappdoor.ifish.TabGroup2Activity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.theappdoor.ifish\/com.theappdoor.ifish.iFishLakeSearch}: java.lang.ClassCastException: android.webkit.WebView\n    04-16 13:22:23.970: E\/AndroidRuntime(20896):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)\n    04-16 13:22:23.970: E\/AndroidRuntime(20896):    at android.app.ActivityThread.startActivityNow(ActivityThread.java:1491)\n    04-16 13:22:23.970: E\/AndroidRuntime(20896):    at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)\n    04-16 13:22:23.970: E\/AndroidRuntime(20896):    at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)\n    04-16 13:22:23.970: E\/AndroidRuntime(20896):    at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:657)\n    04-16 13:22:23.970: E\/AndroidRuntime(20896):    at android.widget.TabHost.setCurrentTab(TabHost.java:329)\n    04-16 13:22:23.970: E\/AndroidRuntime(20896):    at com.theappdoor.ifish.iFishHome.goToLakeSearch(iFishHome.java:20)\n    04-16 13:22:23.970: E\/AndroidRuntime(20896):    ... 14 more\n    04-16 13:22:23.970: E\/AndroidRuntime(20896): Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.theappdoor.ifish\/com.theappdoor.ifish.iFishLakeSearch}: java.lang.ClassCastException: android.webkit.WebView\n    04-16 13:22:23.970: E\/AndroidRuntime(20896):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)\n    04-16 13:22:23.970: E\/AndroidRuntime(20896):    at android.app.ActivityThread.startActivityNow(ActivityThread.java:1491)\n    04-16 13:22:23.970: E\/AndroidRuntime(20896):    at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)\n    04-16 13:22:23.970: E\/AndroidRuntime(20896):    at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)\n    04-16 13:22:23.970: E\/AndroidRuntime(20896):    at com.theappdoor.ifish.TabGroupActivity.startChildActivity(TabGroupActivity.java:116)\n    04-16 13:22:23.970: E\/AndroidRuntime(20896):    at com.theappdoor.ifish.TabGroup2Activity.onCreate(TabGroup2Activity.java:10)\n    04-16 13:22:23.970: E\/AndroidRuntime(20896):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)\n    04-16 13:22:23.970: E\/AndroidRuntime(20896):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)\n    04-16 13:22:23.970: E\/AndroidRuntime(20896):    ... 20 more\n    04-16 13:22:23.970: E\/AndroidRuntime(20896): Caused by: java.lang.ClassCastException: android.webkit.WebView\n    04-16 13:22:23.970: E\/AndroidRuntime(20896):    at com.theappdoor.ifish.iFishLakeSearch.onCreate(iFishLakeSearch.java:61)\n    04-16 13:22:23.970: E\/AndroidRuntime(20896):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)\n    04-16 13:22:23.970: E\/AndroidRuntime(20896):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)\n    04-16 13:22:23.970: E\/AndroidRuntime(20896):    ... 27 more\n    04-16 13:22:44.244: I\/Process(20896): Sending signal. PID: 20896 SIG: 9\n<\/code><\/pre>\n<ol>\n<li>\n<p>android:layout_above=&#8221;@+id\/lakeSearchAdWebView&#8221; means the view will be directly above lakeSearchAdWebView. Since you stated you put that in two different views, there is a problem, since they cannot both be directly above lakeSearchAdWebView.<\/p>\n<p>Therefore to fix, simply put: <code>android:layout_above=\"@+id\/lakeSearchAdWebView\"<\/code> in the lakeSearchDetailsWebView<\/p>\n<p>and then put <code>android:layout_above:\"@+id\/lakeSearchDetailsWebView\"<\/code> in the lakeSearchScrollView<\/p>\n<p>Doing it this way will have your views in the order (from top to bottom) lakeSearchScrollView, lakeSearchDetailsWebView, lakeSearchAdWebView<\/p>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2014-01-05 10:09:46. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>&#8211;UPDATE&#8211; April 17th, 2012 It seems that it is only crashing when I add: android:layout_above=&#8221;@+id\/lakeSearchAdWebView&#8221; to lakeSearchScrollView, adding it to just lakeSearchDetailsWebView works fine. Here&#8217;s my layout: I want to have lakeSearchScrollView and lakeSearchDetailsWebView setup so that they are always above lakeSearchAdWebview, so lakeSearchAdWebview is always visible. Only ONE of lakeSearchScrollView and lakeSearchDetailsWebView is visible [&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-2317","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2317","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=2317"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2317\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2317"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2317"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2317"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}