I keep getting this error on emulator:
I copied this from a tutorial and still won’t work. When I run my app it says – Unfortunately, lastRide has stopped. Any Ideas?
No errors are given in the console though.
main.xml
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:ignore="HardcodedText" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:id="@+id/fr"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<CheckBox android:text="rawted" />
<CheckBox android:text="rawted" />
<CheckBox android:text="rawted" />
<CheckBox android:text="rawted" />
</LinearLayout>
</LinearLayout>
</TabHost>
lastRideActivity.java
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost mTabHost = getTabHost();
mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator("TAB 1")
.setContent(R.id.fr));
}
You need to move
setContentViewso that it occurs before you call for the tabhost.When you use
getTabHostthe framework is trying to find the widget in the active view, but can’t because no view has been set yet.