RelativeLayout layout_above crashing app-Collection of common programming errors
–UPDATE– April 17th, 2012
It seems that it is only crashing when I add:
android:layout_above="@+id/lakeSearchAdWebView"
to lakeSearchScrollView, adding it to just lakeSearchDetailsWebView works fine.
Here’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 at a time, that’s whey they’re setup to be sitting on top of eachother.
If I add the following line to lakeSearchScrollView, the apps crashes:
android:layout_above="@+id/lakeSearchAdWebView"
Can anyone tell me what I’m doing wrong? I’m still quite new to Android so I’m thinking it’s probably a newbie mistake… thanks in advance!
–UPDATE– Source Code:
package com.theappdoor.ifish;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.TabActivity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ScrollView;
import android.widget.TabHost;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import android.util.Log;
public class iFishLakeSearch extends Activity {
private EditText searchBar;
private TableLayout resultsTableLayout;
private DataHelper dh;
private iFishLakeDetails iFishLD;
private Button lakeSearchBTN;
private ScrollView searchScrollView;
private WebView detailsWebView;
private String lake_id;
private WebView lakeSearchAdWebView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.lakesearch);
//This sets the context to the be of the parent, which is what we want
View viewToLoad = LayoutInflater.from(this.getParent()).inflate(R.layout.lakesearch, null);
setContentView(viewToLoad);
//setup vars
this.dh = new DataHelper(this);
this.iFishLD = new iFishLakeDetails(this);
// connect our elements from the UI XML
this.searchBar = (EditText) findViewById(R.id.searchBar); //LINE 61
this.resultsTableLayout = (TableLayout) findViewById(R.id.resultsTableLayout);
this.lakeSearchBTN = (Button) findViewById(R.id.lakeSearchSearchBTN);
this.lakeSearchBTN.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
lakeSearch(v);
}
});
this.searchScrollView = (ScrollView) findViewById(R.id.lakeSearchScrollView);
this.detailsWebView = (WebView) findViewById(R.id.lakeSearchDetailsWebView);
WebSettings webSettings = this.detailsWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
this.detailsWebView.setWebViewClient(new MyWebViewClient());
this.detailsWebView.addJavascriptInterface(new JavaScriptInterface(this), "Android");
this.detailsWebView.loadUrl("file:///android_asset/webassets/index.html");
this.lakeSearchAdWebView = (WebView)findViewById(R.id.lakeSearchAdWebView);
webSettings = this.lakeSearchAdWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
this.lakeSearchAdWebView.loadUrl(this.getString(R.string.server)+"/iFish_ads/");
}
Line 61:
this.searchBar = (EditText) findViewById(R.id.searchBar);
–UPDATE–
Crash Log:
04-16 13:22:23.951: D/AndroidRuntime(20896): Shutting down VM
04-16 13:22:23.951: W/dalvikvm(20896): threadid=1: thread exiting with uncaught exception (group=0x40015578)
04-16 13:22:23.970: E/AndroidRuntime(20896): FATAL EXCEPTION: main
04-16 13:22:23.970: E/AndroidRuntime(20896): java.lang.IllegalStateException: Could not execute method of the activity
04-16 13:22:23.970: E/AndroidRuntime(20896): at android.view.View$1.onClick(View.java:2154)
04-16 13:22:23.970: E/AndroidRuntime(20896): at android.view.View.performClick(View.java:2538)
04-16 13:22:23.970: E/AndroidRuntime(20896): at android.view.View$PerformClick.run(View.java:9152)
04-16 13:22:23.970: E/AndroidRuntime(20896): at android.os.Handler.handleCallback(Handler.java:587)
04-16 13:22:23.970: E/AndroidRuntime(20896): at android.os.Handler.dispatchMessage(Handler.java:92)
04-16 13:22:23.970: E/AndroidRuntime(20896): at android.os.Looper.loop(Looper.java:123)
04-16 13:22:23.970: E/AndroidRuntime(20896): at android.app.ActivityThread.main(ActivityThread.java:3687)
04-16 13:22:23.970: E/AndroidRuntime(20896): at java.lang.reflect.Method.invokeNative(Native Method)
04-16 13:22:23.970: E/AndroidRuntime(20896): at java.lang.reflect.Method.invoke(Method.java:507)
04-16 13:22:23.970: E/AndroidRuntime(20896): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
04-16 13:22:23.970: E/AndroidRuntime(20896): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
04-16 13:22:23.970: E/AndroidRuntime(20896): at dalvik.system.NativeStart.main(Native Method)
04-16 13:22:23.970: E/AndroidRuntime(20896): Caused by: java.lang.reflect.InvocationTargetException
04-16 13:22:23.970: E/AndroidRuntime(20896): at java.lang.reflect.Method.invokeNative(Native Method)
04-16 13:22:23.970: E/AndroidRuntime(20896): at java.lang.reflect.Method.invoke(Method.java:507)
04-16 13:22:23.970: E/AndroidRuntime(20896): at android.view.View$1.onClick(View.java:2149)
04-16 13:22:23.970: E/AndroidRuntime(20896): ... 11 more
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
04-16 13:22:23.970: E/AndroidRuntime(20896): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
04-16 13:22:23.970: E/AndroidRuntime(20896): at android.app.ActivityThread.startActivityNow(ActivityThread.java:1491)
04-16 13:22:23.970: E/AndroidRuntime(20896): at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
04-16 13:22:23.970: E/AndroidRuntime(20896): at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
04-16 13:22:23.970: E/AndroidRuntime(20896): at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:657)
04-16 13:22:23.970: E/AndroidRuntime(20896): at android.widget.TabHost.setCurrentTab(TabHost.java:329)
04-16 13:22:23.970: E/AndroidRuntime(20896): at com.theappdoor.ifish.iFishHome.goToLakeSearch(iFishHome.java:20)
04-16 13:22:23.970: E/AndroidRuntime(20896): ... 14 more
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
04-16 13:22:23.970: E/AndroidRuntime(20896): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
04-16 13:22:23.970: E/AndroidRuntime(20896): at android.app.ActivityThread.startActivityNow(ActivityThread.java:1491)
04-16 13:22:23.970: E/AndroidRuntime(20896): at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
04-16 13:22:23.970: E/AndroidRuntime(20896): at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
04-16 13:22:23.970: E/AndroidRuntime(20896): at com.theappdoor.ifish.TabGroupActivity.startChildActivity(TabGroupActivity.java:116)
04-16 13:22:23.970: E/AndroidRuntime(20896): at com.theappdoor.ifish.TabGroup2Activity.onCreate(TabGroup2Activity.java:10)
04-16 13:22:23.970: E/AndroidRuntime(20896): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-16 13:22:23.970: E/AndroidRuntime(20896): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
04-16 13:22:23.970: E/AndroidRuntime(20896): ... 20 more
04-16 13:22:23.970: E/AndroidRuntime(20896): Caused by: java.lang.ClassCastException: android.webkit.WebView
04-16 13:22:23.970: E/AndroidRuntime(20896): at com.theappdoor.ifish.iFishLakeSearch.onCreate(iFishLakeSearch.java:61)
04-16 13:22:23.970: E/AndroidRuntime(20896): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-16 13:22:23.970: E/AndroidRuntime(20896): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
04-16 13:22:23.970: E/AndroidRuntime(20896): ... 27 more
04-16 13:22:44.244: I/Process(20896): Sending signal. PID: 20896 SIG: 9
-
android:layout_above=”@+id/lakeSearchAdWebView” 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.
Therefore to fix, simply put:
android:layout_above="@+id/lakeSearchAdWebView"
in the lakeSearchDetailsWebViewand then put
android:layout_above:"@+id/lakeSearchDetailsWebView"
in the lakeSearchScrollViewDoing it this way will have your views in the order (from top to bottom) lakeSearchScrollView, lakeSearchDetailsWebView, lakeSearchAdWebView