En una activity estoy creando un tabhost, pero cuando lo ejecuto me sale un error.
He buscado alguna solución pero no encuentro nada al respecto.
¿Alguien me podría indicar que me genera el problema?, de antemano muchas gracias
xml
Código XML:
Ver original
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_gravity="center_vertical" android:layout_width="match_parent" android:layout_height="wrap_content"> <RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content" 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.app8semanas.MainProgreso" > <TabHost android:id="@android:id/tabhost" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignParentLeft="true" android:layout_below="@+id/txt1" android:layout_marginTop="14dp" > <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TabWidget android:id="@android:id/tabs" android:layout_width="match_parent" android:layout_height="wrap_content" > </TabWidget> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="match_parent" android:layout_height="match_parent" > <RelativeLayout android:id="@+id/tab1" android:layout_width="match_parent" android:layout_height="374dp" android:orientation="horizontal" > <RadioGroup android:id="@+id/rgactfis" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/txtactfis" > <RadioButton android:id="@+id/rbaf1" android:layout_width="wrap_content" android:checked="true" android:text="@string/hice_15_minutos" /> <RadioButton android:id="@+id/rbaf2" android:layout_width="wrap_content" android:text="@string/hice_30_minutos" /> <RadioButton android:id="@+id/rbaf3" android:layout_width="wrap_content" android:text="@string/hice_45_minutos" /> </RadioGroup> <RelativeLayout android:id="@+id/tab2" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" > <RadioGroup android:id="@+id/rgfruveg" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/txtfruveg" > <RadioButton android:id="@+id/rbfv1" android:layout_width="wrap_content" android:checked="true" android:text="@string/si" /> <RadioButton android:id="@+id/rbfv2" android:layout_width="wrap_content" android:text="@string/no" /> </RadioGroup> </RelativeLayout> <RelativeLayout android:id="@+id/tab3" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" > <RadioGroup android:id="@+id/rgdormir" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/txtdormir" > <RadioButton android:id="@+id/rbd1" android:layout_width="wrap_content" android:checked="true" android:text="@string/si" /> <RadioButton android:id="@+id/rbd2" android:layout_width="wrap_content" android:text="@string/no" /> </RadioGroup> </RelativeLayout> </FrameLayout> </LinearLayout> </TabHost> </RelativeLayout> </ScrollView>
java:
Código Java:
Ver original
public class MainProgreso extends Activity implements OnClickListener { private TabHost th; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.progreso); th=(TabHost)findViewById(android.R.id.tabhost); th.setup(); TabSpec ts1=th.newTabSpec("Tab1"); ts1.setIndicator("Actividad_Fisica"); ts1.setContent(R.id.tab1); TabSpec ts2=th.newTabSpec("Tab2"); ts1.setIndicator("Frutas_Verduras"); ts1.setContent(R.id.tab2); TabSpec ts3=th.newTabSpec("Tab3"); ts1.setIndicator("Sueño"); ts1.setContent(R.id.tab3); th.addTab(ts1); th.addTab(ts2); th.addTab(ts3); } // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } @Override { } }
el error
Cita:
02-17 16:20:25.264: E/AndroidRuntime(918): FATAL EXCEPTION: main
02-17 16:20:25.264: E/AndroidRuntime(918): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.app8semanas/com.example.app8semanas.MainProgreso}: java.lang.IllegalArgumentException: you must specify a way to create the tab indicator.
02-17 16:20:25.264: E/AndroidRuntime(918): at android.app.ActivityThread.performLaunchActivity(A ctivityThread.java:1955)
02-17 16:20:25.264: E/AndroidRuntime(918): at android.app.ActivityThread.handleLaunchActivity(Ac tivityThread.java:1980)
02-17 16:20:25.264: E/AndroidRuntime(918): at android.app.ActivityThread.access$600(ActivityThre ad.java:122)
02-17 16:20:25.264: E/AndroidRuntime(918): at android.app.ActivityThread$H.handleMessage(Activit yThread.java:1146)
02-17 16:20:25.264: E/AndroidRuntime(918): at android.os.Handler.dispatchMessage(Handler.java:99 )
02-17 16:20:25.264: E/AndroidRuntime(918): at android.os.Looper.loop(Looper.java:137)
02-17 16:20:25.264: E/AndroidRuntime(918): at android.app.ActivityThread.main(ActivityThread.jav a:4340)
02-17 16:20:25.264: E/AndroidRuntime(918): at java.lang.reflect.Method.invokeNative(Native Method)
02-17 16:20:25.264: E/AndroidRuntime(918): at java.lang.reflect.Method.invoke(Method.java:511)
02-17 16:20:25.264: E/AndroidRuntime(918): at com.android.internal.os.ZygoteInit$MethodAndArgsCa ller.run(ZygoteInit.java:784)
02-17 16:20:25.264: E/AndroidRuntime(918): at com.android.internal.os.ZygoteInit.main(ZygoteInit .java:551)
02-17 16:20:25.264: E/AndroidRuntime(918): at dalvik.system.NativeStart.main(Native Method)
02-17 16:20:25.264: E/AndroidRuntime(918): Caused by: java.lang.IllegalArgumentException: you must specify a way to create the tab indicator.
02-17 16:20:25.264: E/AndroidRuntime(918): at android.widget.TabHost.addTab(TabHost.java:217)
02-17 16:20:25.264: E/AndroidRuntime(918): at com.example.app8semanas.MainProgreso.onCreate(Main Progreso.java:36)
02-17 16:20:25.264: E/AndroidRuntime(918): at android.app.Activity.performCreate(Activity.java:4 465)
02-17 16:20:25.264: E/AndroidRuntime(918): at android.app.Instrumentation.callActivityOnCreate(I nstrumentation.java:1049)
02-17 16:20:25.264: E/AndroidRuntime(918): at android.app.ActivityThread.performLaunchActivity(A ctivityThread.java:1919)
02-17 16:20:25.264: E/AndroidRuntime(918): ... 11 more
02-17 16:20:25.264: E/AndroidRuntime(918): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.app8semanas/com.example.app8semanas.MainProgreso}: java.lang.IllegalArgumentException: you must specify a way to create the tab indicator.
02-17 16:20:25.264: E/AndroidRuntime(918): at android.app.ActivityThread.performLaunchActivity(A ctivityThread.java:1955)
02-17 16:20:25.264: E/AndroidRuntime(918): at android.app.ActivityThread.handleLaunchActivity(Ac tivityThread.java:1980)
02-17 16:20:25.264: E/AndroidRuntime(918): at android.app.ActivityThread.access$600(ActivityThre ad.java:122)
02-17 16:20:25.264: E/AndroidRuntime(918): at android.app.ActivityThread$H.handleMessage(Activit yThread.java:1146)
02-17 16:20:25.264: E/AndroidRuntime(918): at android.os.Handler.dispatchMessage(Handler.java:99 )
02-17 16:20:25.264: E/AndroidRuntime(918): at android.os.Looper.loop(Looper.java:137)
02-17 16:20:25.264: E/AndroidRuntime(918): at android.app.ActivityThread.main(ActivityThread.jav a:4340)
02-17 16:20:25.264: E/AndroidRuntime(918): at java.lang.reflect.Method.invokeNative(Native Method)
02-17 16:20:25.264: E/AndroidRuntime(918): at java.lang.reflect.Method.invoke(Method.java:511)
02-17 16:20:25.264: E/AndroidRuntime(918): at com.android.internal.os.ZygoteInit$MethodAndArgsCa ller.run(ZygoteInit.java:784)
02-17 16:20:25.264: E/AndroidRuntime(918): at com.android.internal.os.ZygoteInit.main(ZygoteInit .java:551)
02-17 16:20:25.264: E/AndroidRuntime(918): at dalvik.system.NativeStart.main(Native Method)
02-17 16:20:25.264: E/AndroidRuntime(918): Caused by: java.lang.IllegalArgumentException: you must specify a way to create the tab indicator.
02-17 16:20:25.264: E/AndroidRuntime(918): at android.widget.TabHost.addTab(TabHost.java:217)
02-17 16:20:25.264: E/AndroidRuntime(918): at com.example.app8semanas.MainProgreso.onCreate(Main Progreso.java:36)
02-17 16:20:25.264: E/AndroidRuntime(918): at android.app.Activity.performCreate(Activity.java:4 465)
02-17 16:20:25.264: E/AndroidRuntime(918): at android.app.Instrumentation.callActivityOnCreate(I nstrumentation.java:1049)
02-17 16:20:25.264: E/AndroidRuntime(918): at android.app.ActivityThread.performLaunchActivity(A ctivityThread.java:1919)
02-17 16:20:25.264: E/AndroidRuntime(918): ... 11 more