2 Tabs Not Working, Crashes Application
<p>As a beginner, I wanted to learn the tabbed layout of android using tabhost/tabwidget, though I've read some posts that its already deprecated. So... Basically, what I was trying to achieve is to have a layout with two tabs who will both show a webview with different content each. But everytime I try to access that layout, my app crashes.</p>

<p>Here's what it says in my Logcat:</p>

<p>LOGCAT:
<code></p>

<pre><code>   04-09 22:30:53.628: E/AndroidRuntime(10406): FATAL EXCEPTION: main
04-09 22:30:53.628: E/AndroidRuntime(10406): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nicx.amazing/com.nicx.amazing.TabActivity}: java.lang.IllegalStateException: Already attached
04-09 22:30:53.628: E/AndroidRuntime(10406):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1967)
04-09 22:30:53.628: E/AndroidRuntime(10406):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
04-09 22:30:53.628: E/AndroidRuntime(10406):    at android.app.ActivityThread.access$600(ActivityThread.java:127)
04-09 22:30:53.628: E/AndroidRuntime(10406):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
04-09 22:30:53.628: E/AndroidRuntime(10406):    at android.os.Handler.dispatchMessage(Handler.java:99)
04-09 22:30:53.628: E/AndroidRuntime(10406):    at android.os.Looper.loop(Looper.java:137)
04-09 22:30:53.628: E/AndroidRuntime(10406):    at android.app.ActivityThread.main(ActivityThread.java:4448)
04-09 22:30:53.628: E/AndroidRuntime(10406):    at java.lang.reflect.Method.invokeNative(Native Method)
04-09 22:30:53.628: E/AndroidRuntime(10406):    at java.lang.reflect.Method.invoke(Method.java:511)
04-09 22:30:53.628: E/AndroidRuntime(10406):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:823)
04-09 22:30:53.628: E/AndroidRuntime(10406):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:590)
04-09 22:30:53.628: E/AndroidRuntime(10406):    at dalvik.system.NativeStart.main(Native Method)
04-09 22:30:53.628: E/AndroidRuntime(10406): Caused by: java.lang.IllegalStateException: Already attached
04-09 22:30:53.628: E/AndroidRuntime(10406):    at android.support.v4.app.FragmentManagerImpl.attachActivity(FragmentManager.java:1844)
04-09 22:30:53.628: E/AndroidRuntime(10406):    at android.support.v4.app.FragmentActivity.onCreate(FragmentActivity.java:193)
04-09 22:30:53.628: E/AndroidRuntime(10406):    at com.nicx.amazing.TabActivity.onCreate(TabActivity.java:15)
04-09 22:30:53.628: E/AndroidRuntime(10406):    at android.app.Activity.performCreate(Activity.java:4465)
04-09 22:30:53.628: E/AndroidRuntime(10406):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
04-09 22:30:53.628: E/AndroidRuntime(10406):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931)
04-09 22:30:53.628: E/AndroidRuntime(10406):    ... 11 more
</code></pre>

<p></code></p>

<p>Here's what I have in my TabActivity.java:</p>

<p><code></p>

<pre><code>import android.os.Bundle;
import android.support.v4.app.*;
import android.widget.TabHost;

public class TabActivity extends FragmentActivity {

        TabHost tHost;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

            tHost = (TabHost) findViewById(android.R.id.tabhost);
            tHost.setup();

            TabHost.TabSpec fb = tHost.newTabSpec("facebook");
            fb.setIndicator("Facebook", null);
            fb.setContent(new DummyTabContent(getBaseContext()));
            tHost.addTab(fb);

            TabHost.TabSpec tw = tHost.newTabSpec("twitter");
            tw.setIndicator("Twitter", null);
            tw.setContent(new DummyTabContent(getBaseContext()));
            tHost.addTab(tw);

        }
}
</code></pre>

<p></code>
NOTE: I still haven't figured out how to place a webview in my tabs, I just want to start first in seeing the layout of my tabs.</p>

<p>I also have this in my activity_tab.xml:</p>

<p><code></p>

<pre><code>&lt;TabHost
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="match_parent"
    android:layout_height="match_parent"&gt;

    &lt;LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"&gt;

        &lt;TabWidget
            android:id="@android:id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0"/&gt;

        &lt;FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_weight="0"/&gt;

        &lt;FrameLayout
            android:id="@+id/realtabcontent"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"/&gt;

    &lt;/LinearLayout&gt;
&lt;/TabHost&gt;
</code></pre>

<p></code></p>

<p>I used <a href="http://wptrafficanalyzer.in/blog/creating-navigation-tabs-using-tabhost-and-fragments-in-android/" rel="nofollow">http://wptrafficanalyzer.in/blog/creating-navigation-tabs-using-tabhost-and-fragments-in-android/</a> as a guide. I just didn't follow its fragments since I am not using it. Can you help me with this?</p>
