title: TabHost defined in layout is giving NullPointerException during setContent
body: <p>I'm trying to modify <code>Tabs1.java</code> from the Android API Demos 16 (and run on an API 16 emulator) to use a standard <code>Activity</code> rather than the deprecated <a href="http://developer.android.com/reference/android/app/TabActivity.html" rel="noreferrer"><code>TabActivity</code></a> class.  I've created a new layout file and modified the code.</p>
  
  <p>The reason I'm trying to use this approach as opposed to the action bar is that the tabs don't apply to the entire screen, only a smaller sub-view.</p>
  
  <p>When I <strong>execute</strong> the code, I'm getting a <code>NullPointerException</code> inside the Android <code>setContent</code> method when executing the following line:</p>
  
  <p><code>tabHost.newTabSpec("tab1").setIndicator("tab1").setContent(R.id.view1)</code> </p>
  
  <p>Any ideas why this might be happening?  Full stack trace is after code and layout. </p>
  
  <p><strong><code>Tabs1VanillaActivity.java</code>:</strong></p>
  
  <pre><code>public class Tabs1 extends Activity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.tabs1);
          TabHost tabHost = (TabHost) findViewById(R.id.tabhost);
  
          tabHost.addTab(tabHost.newTabSpec("tab1")
                  .setIndicator("tab1")
                  .setContent(R.id.view1));
          tabHost.addTab(tabHost.newTabSpec("tab3")
                  .setIndicator("tab2")
                  .setContent(R.id.view2));
          tabHost.addTab(tabHost.newTabSpec("tab3")
                  .setIndicator("tab3")
                  .setContent(R.id.view3));
      }
  }
  </code></pre>
  
  <p><strong>tabs1.xml:</strong>
      
      </p>
  
  <pre><code>    &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="TextView goes here!"
          tools:ignore="HardcodedText" /&gt;
  
      &lt;TabHost
          android:id="@+id/tabhost"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content" &gt;
  
          &lt;LinearLayout
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:orientation="vertical" &gt;
  
              &lt;TabWidget
                  android:id="@android:id/tabs"
                  android:layout_width="fill_parent"
                  android:layout_height="wrap_content" /&gt;
  
              &lt;FrameLayout
                  xmlns:android="http://schemas.android.com/apk/res/android"
                  android:id="@android:id/tabcontent"
                  android:layout_width="match_parent"
                  android:layout_height="match_parent" &gt;
  
                  &lt;TextView
                      android:id="@+id/view1"
                      android:layout_width="match_parent"
                      android:layout_height="match_parent"
                      android:background="@drawable/blue"
                      android:text="@string/tabs_1_tab_1" /&gt;
  
                  &lt;TextView
                      android:id="@+id/view2"
                      android:layout_width="match_parent"
                      android:layout_height="match_parent"
                      android:background="@drawable/red"
                      android:text="@string/tabs_1_tab_2" /&gt;
  
                  &lt;TextView
                      android:id="@+id/view3"
                      android:layout_width="match_parent"
                      android:layout_height="match_parent"
                      android:background="@drawable/green"
                      android:text="@string/tabs_1_tab_3" /&gt;
              &lt;/FrameLayout&gt;
          &lt;/LinearLayout&gt;
      &lt;/TabHost&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p><strong>Stack Trace:</strong></p>
  
  <pre><code>09-18 16:18:22.968: E/AndroidRuntime(1191): FATAL EXCEPTION: main
  09-18 16:18:22.968: E/AndroidRuntime(1191): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.apis/com.example.android.apis.view.Tabs1}: java.lang.NullPointerException
  09-18 16:18:22.968: E/AndroidRuntime(1191):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
  09-18 16:18:22.968: E/AndroidRuntime(1191):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
  09-18 16:18:22.968: E/AndroidRuntime(1191):     at android.app.ActivityThread.access$600(ActivityThread.java:123)
  09-18 16:18:22.968: E/AndroidRuntime(1191):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
  09-18 16:18:22.968: E/AndroidRuntime(1191):     at android.os.Handler.dispatchMessage(Handler.java:99)
  09-18 16:18:22.968: E/AndroidRuntime(1191):     at android.os.Looper.loop(Looper.java:137)
  09-18 16:18:22.968: E/AndroidRuntime(1191):     at android.app.ActivityThread.main(ActivityThread.java:4424)
  09-18 16:18:22.968: E/AndroidRuntime(1191):     at java.lang.reflect.Method.invokeNative(Native Method)
  09-18 16:18:22.968: E/AndroidRuntime(1191):     at java.lang.reflect.Method.invoke(Method.java:511)
  09-18 16:18:22.968: E/AndroidRuntime(1191):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
  09-18 16:18:22.968: E/AndroidRuntime(1191):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
  09-18 16:18:22.968: E/AndroidRuntime(1191):     at dalvik.system.NativeStart.main(Native Method)
  09-18 16:18:22.968: E/AndroidRuntime(1191): Caused by: java.lang.NullPointerException
  09-18 16:18:22.968: E/AndroidRuntime(1191):     at android.widget.TabHost$ViewIdContentStrategy.&lt;init&gt;(TabHost.java:617)
  09-18 16:18:22.968: E/AndroidRuntime(1191):     at android.widget.TabHost$ViewIdContentStrategy.&lt;init&gt;(TabHost.java:612)
  09-18 16:18:22.968: E/AndroidRuntime(1191):     at android.widget.TabHost$TabSpec.setContent(TabHost.java:461)
  09-18 16:18:22.968: E/AndroidRuntime(1191):     at com.example.android.apis.view.Tabs1.onCreate(Tabs1.java:42)
  09-18 16:18:22.968: E/AndroidRuntime(1191):     at android.app.Activity.performCreate(Activity.java:4465)
  09-18 16:18:22.968: E/AndroidRuntime(1191):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
  09-18 16:18:22.968: E/AndroidRuntime(1191):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
  09-18 16:18:22.968: E/AndroidRuntime(1191):     ... 11 more
  </code></pre>