Note that there are some explanatory texts on larger screens.

plurals
  1. POerror when add tab
    primarykey
    data
    text
    <p>I am trying to make vertical tabs using this code in oncreate i try to add tabs and in tabHandler its an button onclick to set which tab to view</p> <pre><code>@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tabHost = (TabHost)findViewById(android.R.id.tabhost); TabSpec firstTabSpec = tabHost.newTabSpec("tid1"); TabSpec secondTabSpec = tabHost.newTabSpec("tid2"); firstTabSpec.setIndicator("First Tab Name").setContent(new Intent(this,PageOne.class)); secondTabSpec.setIndicator("Second Tab Name").setContent(new Intent(this,PageTwo.class)); tabHost.addTab(firstTabSpec); tabHost.addTab(secondTabSpec); } public void tabHandler(View target){ //artistButton.setSelected(false); // albumButton.setSelected(false); //songButton.setSelected(false); if(target.getId() == R.id.artist_id){ tabHost.setCurrentTab(0); // artistButton.setSelected(true); } else if(target.getId() == R.id.album_id){ tabHost.setCurrentTab(1); // albumButton.setSelected(true); } else if(target.getId() == R.id.song_id){ tabHost.setCurrentTab(2); // songButton.setSelected(true); } } </code></pre> <p>and this is the main.xml</p> <pre><code>&lt;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"&gt; &lt;LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent"&gt; &lt;FrameLayout android:layout_width="0dip" android:layout_height="fill_parent" android:layout_weight="0.2"&gt; &lt;TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" android:visibility="gone"/&gt; &lt;LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"&gt; &lt;Button android:layout_height="0dip" android:layout_width="fill_parent" android:layout_weight="1.0" android:id="@+id/artist_id" android:onClick="tabHandler"/&gt; &lt;Button android:layout_height="0dip" android:layout_width="fill_parent" android:layout_weight="1.0" android:id="@+id/album_id" android:onClick="tabHandler"/&gt; &lt;Button android:layout_height="0dip" android:layout_width="fill_parent" android:layout_weight="1.0" android:id="@+id/song_id" android:onClick="tabHandler"/&gt; &lt;/LinearLayout&gt; &lt;/FrameLayout&gt; &lt;FrameLayout android:id="@android:id/tabcontent" android:layout_width="0dip" android:layout_height="fill_parent" android:layout_weight="0.8"/&gt; </code></pre> <p> </p> <p>but it throw this exception on run </p> <pre><code>01-21 19:01:03.655: E/AndroidRuntime(1101): FATAL EXCEPTION: main 01-21 19:01:03.655: E/AndroidRuntime(1101): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.exampleexample. .MainActivity}: java.lang.NullPointerException </code></pre> <p>when these two lines added: tabHost.addTab(firstTabSpec); tabHost.addTab(secondTabSpec);</p> <p>but i dont know why</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload