XML : I can't use tabs on android studio

i'm trying to build a small app with android studio and i'm having a problem with tabs. When i start the app, the system immediatly shuts down my app. Here is the code:

  public class main extends AppCompatActivity {    @Override  protected void onCreate(Bundle savedInstanceState) {      super.onCreate(savedInstanceState);      setContentView(R.layout.activity_main);        TabHost tabHost = (TabHost)findViewById(R.id.tabHost);      tabHost.setup();        TabHost.TabSpec D20 = tabHost.newTabSpec("D20");      D20.setContent(R.id.D20);      D20.setIndicator("D20");      tabHost.addTab(D20);        }    

The XML file:

  <?xml version="1.0" encoding="utf-8"?>  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  xmlns:tools="http://schemas.android.com/tools"  android:layout_width="match_parent"  android:layout_height="match_parent"  android:paddingBottom="@dimen/activity_vertical_margin"  android:paddingLeft="@dimen/activity_horizontal_margin"  android:paddingRight="@dimen/activity_horizontal_margin"  android:paddingTop="@dimen/activity_vertical_margin"  tools:context="com.example.ahmad.d20.main">    <TabHost xmlns:android="http://schemas.android.com/apk/res/android"      xmlns:app="http://schemas.android.com/apk/res-auto"      xmlns:tools="http://schemas.android.com/tools"      android:layout_width="fill_parent"      android:layout_height="fill_parent"      android:id="@+id/tabHost"       >        <TabWidget          android:layout_width="fill_parent"          android:layout_height="wrap_content"          android:id="@android:id/tabs"          />      <FrameLayout          android:layout_width="fill_parent"          android:layout_height="fill_parent"          android:id="@android:id/tabcontent"          >          <LinearLayout              android:layout_width="fill_parent"              android:layout_height="fill_parent"              android:id="@+id/D20"              android:paddingTop="60px"              android:orientation="horizontal"              android:onClick="rodaD">              </LinearLayout>          </FrameLayout>  </TabHost></RelativeLayout>    

The problem occurs when i add a tabspec, i have no idea why.

No comments:

Post a Comment