Issue with displaying TabHost Layout in new Intent

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Issue with displaying TabHost Layout in new Intent

Postby faisal___ » Fri Feb 19, 2010 11:27 am

Dear Android folks,

This post was initially posted in the wrong forum. 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:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <activity android:name=".NextActivity" android:label="@string/app_name" >
  2.  
Parsed in 0.000 seconds, using GeSHi 1.0.8.4


Within the first activity (MainActivity), I start the second intent (NextActivity), with extras, as follows:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Intent nextActivity = new Intent(MainActivity.this,NextActivity.class);
  2. Bundle b_next=new Bundle();
  3.  
  4. b_next.putString("s_string", myString);
  5.  
  6. nextActivity.putExtras(b_next);
  7.  
Parsed in 0.030 seconds, using GeSHi 1.0.8.4


In my NextActivity.java file, I get the extras and try to display the TabHost View:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class NextActivity extends TabActivity {
  2.         @Override
  3.         public void onCreate(Bundle savedInstanceState) {
  4.         super.onCreate(savedInstanceState);
  5.  
  6.         String myString;
  7.         Bundle b_initial;
  8.        
  9.         b_initial = getIntent().getExtras();
  10.                
  11.         myString = b_initial.getString("s_string");
  12.  
  13.         setContentView(R.layout.main);
  14.  
  15.         }
  16. }
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


I get the same error with using the TabHost example on the Android Developer site (Hellow View):

Main.xml:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <TabHost xmlns:android="http://schemas.android.com/apk/res/android"
  3.    android:id="@android:id/tabhost"
  4.    android:layout_width="fill_parent"
  5.    android:layout_height="fill_parent">
  6.     <LinearLayout
  7.        android:orientation="vertical"
  8.        android:layout_width="fill_parent"
  9.        android:layout_height="fill_parent">
  10.         <TabWidget
  11.            android:id="@android:id/tabs"
  12.            android:layout_width="fill_parent"
  13.            android:layout_height="wrap_content" />
  14.         <FrameLayout
  15.            android:id="@android:id/tabcontent"
  16.            android:layout_width="fill_parent"
  17.            android:layout_height="fill_parent">
  18.             <TextView
  19.                android:id="@+id/textview1"
  20.                android:layout_width="fill_parent"
  21.                android:layout_height="fill_parent"
  22.                android:text="this is a tab" />
  23.             <TextView
  24.                android:id="@+id/textview2"
  25.                android:layout_width="fill_parent"
  26.                android:layout_height="fill_parent"
  27.                android:text="this is another tab" />
  28.             <TextView
  29.                android:id="@+id/textview3"
  30.                android:layout_width="fill_parent"
  31.                android:layout_height="fill_parent"
  32.                android:text="this is a third tab" />
  33.         </FrameLayout>
  34.     </LinearLayout>
  35. </TabHost>
Parsed in 0.005 seconds, using GeSHi 1.0.8.4


Thanks in advance folks...
Faisal...
faisal___
Freshman
Freshman
 
Posts: 8
Joined: Thu Feb 04, 2010 3:27 pm
Location: Swindon, UK

Top

... clarification ...

Postby faisal___ » Fri Feb 19, 2010 5:20 pm

Dear Android developers,

I made a mistake in my previous post. This is what I get from LogCat as the new view tries to load in the new intent:

Code: Select all
java.lang.NullPointerException
     at android.widget.TabHost.dispatchWindowFocusChanged(TabHost.java
     at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java
     at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java
     at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java
     at android.view.ViewRoot.handleMessage(ViewRoot.java
     at android.os.Handler.dispatchMessage(Handler.java
     at android.os.Looper.loop(Looper.java
     at android.app.ActivityThread.main(ActivityThread.java
     at java.lang.reflect.Method.invokeNative(Native Method)
     at java.lang.reflect.Method.invoke(Method.java
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java
     at dalvik.system.NativeStart.main(Native Method)
Faisal...
faisal___
Freshman
Freshman
 
Posts: 8
Joined: Thu Feb 04, 2010 3:27 pm
Location: Swindon, UK

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 8 guests