I am having an issue with using TabHost in a new Intent of type TabActivity which I hope you can point me in the right direction. Funnily it works fine when I try to view it in the original Intent : setContentView(R.layout.main)
I get a "forced closed" and within logcat, I get the following error even though my Tabhost id = "@android:id/tabhost":
02-18 22:23:11.937: ERROR/AndroidRuntime(5944): Caused by: java.lang.RuntimeException: Your content must have a TabHost whose id attribute is 'android.R.id.tabhost'
I have declared the second intent in the Manifest.xml file: XML:
<activity android:name=".NextActivity" android:label="@string/app_name" >
Within the first activity (MainActivity), I start the second intent (NextActivity), with extras, as follows:
Intent nextActivity = new Intent(MainActivity.this,NextActivity.class);
Bundle b_next=new Bundle();
b_next.putString("s_string", myString);
nextActivity.putExtras(b_next);
In my NextActivity.java file, I get the extras and try to display the TabHost View:
public class NextActivity extends TabActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String myString;
Bundle b_initial;
b_initial = getIntent().getExtras();
myString = b_initial.getString("s_string");
setContentView(R.layout.main);
}
}
I get the same error with using the TabHost example on the Android Developer site (Hellow View):
Main.xml:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/textview1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="this is a tab" />
<TextView
android:id="@+id/textview2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="this is another tab" />
<TextView
android:id="@+id/textview3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="this is a third tab" />
</FrameLayout>
</LinearLayout>
</TabHost>
Thanks in advance folks...
CLARIFICATION: This is what I really get from LogCat:
java.lang.NullPointerException
at android.widget.TabHost.dispatchWindowFocusChanged(TabHost.java 285) at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java 640) at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java 640) at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java 640) at android.view.ViewRoot.handleMessage(ViewRoot.java 1645) at android.os.Handler.dispatchMessage(Handler.java 99) at android.os.Looper.loop(Looper.java 123) at android.app.ActivityThread.main(ActivityThread.java 3948) at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java 521) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java 782) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java 540) at dalvik.system.NativeStart.main(Native Method)
"public class NextActivity extends TabActivity"
--change TabActivity to ActivityGroup.when problem happen when you want wo run tabhost in tabhost.it is ok.
I also encountered this problem. I had an XML file that wasn't linked against my code properly in my res/layout. When I fixed the naming, the problem went away.
I am experiencing the same error in a team-project, when using SVN. Sometimes, eclipse uploads classes.dex and resources.ap_ from the bin folder of the project and others get it via SVN update.
Since these binary files are generated on the individual machines with individual code, thats probably where the error comes from.
Cleaning the project files (Project -> Clean) always solved the issue for us!