title: Tabs inside another Tab( using Fragments) in Android
body: <p>In my app(android 2.1), i have successfully added tabs using Fragments and I use Android Compatibility library v4.</p>
  
  <p>Now i want to add another tab inside one of the fragment tabs, but the tabwidget throws NullPointerException, what i am doing wrong here?</p>
  
  <p>LogCat:</p>
  
  <pre><code>05-08 12:58:57.060: W/dalvikvm(1371): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
  05-08 12:58:57.060: E/AndroidRuntime(1371): Uncaught handler: thread main exiting due to uncaught exception
  05-08 12:58:57.100: E/AndroidRuntime(1371): java.lang.NullPointerException
  05-08 12:58:57.100: E/AndroidRuntime(1371):     at android.widget.TabWidget.dispatchDraw(TabWidget.java:206)
  05-08 12:58:57.100: E/AndroidRuntime(1371):     at android.view.ViewGroup.drawChild(ViewGroup.java:1529)
  05-08 12:58:57.100: E/AndroidRuntime(1371):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
  05-08 12:58:57.100: E/AndroidRuntime(1371):     at android.view.ViewGroup.drawChild(ViewGroup.java:1529)
  05-08 12:58:57.100: E/AndroidRuntime(1371):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
  05-08 12:58:57.100: E/AndroidRuntime(1371):     at android.view.ViewGroup.drawChild(ViewGroup.java:1529)
  05-08 12:58:57.100: E/AndroidRuntime(1371):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
  05-08 12:58:57.100: E/AndroidRuntime(1371):     at android.view.View.draw(View.java:6538)
  05-08 12:58:57.100: E/AndroidRuntime(1371):     at android.view.ViewGroup.drawChild(ViewGroup.java:1531)
  05-08 12:58:57.100: E/AndroidRuntime(1371):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
  05-08 12:58:57.100: E/AndroidRuntime(1371):     at android.view.ViewGroup.drawChild(ViewGroup.java:1529)
  05-08 12:58:57.100: E/AndroidRuntime(1371):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
  05-08 12:58:57.100: E/AndroidRuntime(1371):     at android.view.View.draw(View.java:6538)
  05-08 12:58:57.100: E/AndroidRuntime(1371):     at android.support.v4.view.ViewPager.draw(ViewPager.java:1574)
  05-08 12:58:57.100: E/AndroidRuntime(1371):     at android.view.ViewGroup.drawChild(ViewGroup.java:1531)
  05-08 12:58:57.100: E/AndroidRuntime(1371):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
  05-08 12:58:57.100: E/AndroidRuntime(1371):     at android.view.ViewGroup.drawChild(ViewGroup.java:1529)
  05-08 12:58:57.100: E/AndroidRuntime(1371):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
  05-08 12:58:57.100: E/AndroidRuntime(1371):     at android.view.ViewGroup.drawChild(ViewGroup.java:1529)
  05-08 12:58:57.100: E/AndroidRuntime(1371):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
  05-08 12:58:57.100: E/AndroidRuntime(1371):     at android.view.ViewGroup.drawChild(ViewGroup.java:1529)
  05-08 12:58:57.100: E/AndroidRuntime(1371):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
  05-08 12:58:57.100: E/AndroidRuntime(1371):     at android.view.View.draw(View.java:6538)
  05-08 12:58:57.100: E/AndroidRuntime(1371):     at android.widget.FrameLayout.draw(FrameLayout.java:352)
  05-08 12:58:57.100: E/AndroidRuntime(1371):     at android.view.ViewGroup.drawChild(ViewGroup.java:1531)
  05-08 12:58:57.100: E/AndroidRuntime(1371):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
  05-08 12:58:57.100: E/AndroidRuntime(1371):     at android.view.View.draw(View.java:6538)
  05-08 12:58:57.100: E/AndroidRuntime(1371):     at android.widget.FrameLayout.draw(FrameLayout.java:352)
  05-08 12:58:57.100: E/AndroidRuntime(1371):     at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1830)
  05-08 12:58:57.100: E/AndroidRuntime(1371):     at android.view.ViewRoot.draw(ViewRoot.java:1349)
  05-08 12:58:57.100: E/AndroidRuntime(1371):     at android.view.ViewRoot.performTraversals(ViewRoot.java:1114)
  05-08 12:58:57.100: E/AndroidRuntime(1371):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1633)
  05-08 12:58:57.100: E/AndroidRuntime(1371):     at android.os.Handler.dispatchMessage(Handler.java:99)
  05-08 12:58:57.100: E/AndroidRuntime(1371):     at android.os.Looper.loop(Looper.java:123)
  05-08 12:58:57.100: E/AndroidRuntime(1371):     at android.app.ActivityThread.main(ActivityThread.java:4363)
  05-08 12:58:57.100: E/AndroidRuntime(1371):     at java.lang.reflect.Method.invokeNative(Native Method)
  05-08 12:58:57.100: E/AndroidRuntime(1371):     at java.lang.reflect.Method.invoke(Method.java:521)
  05-08 12:58:57.100: E/AndroidRuntime(1371):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
  05-08 12:58:57.100: E/AndroidRuntime(1371):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
  05-08 12:58:57.100: E/AndroidRuntime(1371):     at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>// sub tab fragment</p>
  
  <pre><code>import android.os.Bundle;
  import android.support.v4.app.Fragment;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.LinearLayout;
  
  public class Tab3Fragment extends Fragment
  {
  
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
          Bundle savedInstanceState) {
      if (container == null) {
          // We have different layouts, and in one of them this
          // fragment's containing frame doesn't exist.  The fragment
          // may still be created from its saved state, but there is
          // no reason to try to create its view hierarchy because it
          // won't be displayed.  Note this is not needed -- we could
          // just run the code below, where we would create and return
          // the view hierarchy; it would just never be used.
          return null;
      }
      return (LinearLayout)inflater.inflate(R.layout.subtab, container, false);
  }
  </code></pre>
  
  <p>}</p>
  
  <p>// subtab.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; 
  
   &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:background="#4C4C4C" &gt;
  &lt;TabHost 
  android:id="@android:id/tabhost" 
  android:layout_width="fill_parent" 
  android:layout_height="fill_parent"
  android:padding="2dp"&gt; 
  
  &lt;LinearLayout 
      android:orientation="vertical" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:padding="5dp"&gt; 
  
      &lt;TabWidget 
          android:id="@android:id/tabs" 
          android:layout_width="fill_parent" 
          android:layout_height="wrap_content" /&gt; 
  
  
      &lt;FrameLayout 
          android:id="@android:id/tabcontent" 
          android:layout_width="fill_parent" 
          android:layout_height="fill_parent" &gt;
  
          &lt;/FrameLayout&gt; 
       &lt;/LinearLayout&gt; 
      &lt;/TabHost&gt;
     &lt;/LinearLayout&gt; 
  </code></pre>