Problem displaying TabHost layout in new intent

I'm having a problem using TabHost in a new intent like TabActivity, which I hope you can point me in the right direction. Funny it works fine when I try to view it in its original intent: setContentView (R.layout.main)

I get a "forced close" and inside logcat, I get the following error, although my Tabhost id = "@android: id / tabhost":

02-18 22: 23: 11.937: ERROR / AndroidRuntime (5944): caused by: java.lang.RuntimeException: your content must have TabHost, whose identifier attribute is "android.R.id.tabhost"

I declared the second intention in the Manifest.xml: XML file:

<activity android:name=".NextActivity" android:label="@string/app_name" > 

As part of the first activity (MainActivity), I launch the second intention (NextActivity) with additional features:

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 additional functions 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 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 guys ...

UPDATE: This is what I really get from LogCat:

java.lang.NullPointerException
      android.widget.TabHost.dispatchWindowFocusChanged(TabHost.java 285)       android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java 640)       android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java 640)       android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java 640)       android.view.ViewRoot.handleMessage(ViewRoot.java 1645)       android.os.Handler.dispatchMessage(Handler.java 99)       android.os.Looper.loop(Looper.java 123)       android.app.ActivityThread.main(ActivityThread.java 3948)       java.lang.reflect.Method.invokeNative( )
      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)       dalvik.system.NativeStart.main( )

+3
9

tabhosts android:id="@+id/tabhost". ?

:

    TabHost t = getTabHost();
    TabSpec tab = t.newTabSpec(label)
                   .setIndicator(label, icon)
                   .setContent(intent);
    t.addTab(tab);
+2

. , :

  • R.
  • , IDE .
  • Profit!
+7

, id :

android:id="@+id/tabs" 

:

android:id="@android:id/tabs"
+3

. XML , res/layout. , .

+2

main.xml, android:id="@android:id/tabhost" , . , res/layout-port/main.xml, main.xml, android: id. , , , . , , .

+2

. ( ProGuard), .

, ProGuard . , ProGuard.

, SapphireSun, ( -, , ).

, , , , .

+1

"public class NextActivity extends TabActivity" - TabActivity ActivityGroup.

, tabhost tabhost.it, .

+1

SVN. eclipse classes.dex resources.ap_ bin , SVN.

, , , .

(Project → Clean) !

0

'ERROR: Unknown option' --no-crunch ''. ADT Eclipse, SDK . SDK Eclipse, .

0

Source: https://habr.com/ru/post/1733497/


All Articles