Visualizzazione stampabile
-
Crash improvviso
Ciao a tutti, ho un problema con questa semplice applicazione, l'unica cosa che è è settare due tab sullo schermo, uno co un analogClock e l'altro come campo vuoto.
Non capisco come mai ma sia sul AVD che sul mio cell (un gratia) va in crash all, avvio.
Allego il codice
XML:
codice:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TabHost android:id="@+id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TabWidget android:id="@+id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<FrameLayout android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingTop="62px"
>
<AnalogClock android:id="@+id/tab1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerHorizontal="true"
/>
<Button android:id="@+id/tab2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="A semi-random button"
/>
</FrameLayout>
</TabHost>
</LinearLayout>
JAVA CODE:
codice:
package prova.TabDemo;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TabHost;
public class TabDemo extends Activity {
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
TabHost tabs = (TabHost)findViewById(R.id.tabhost);
tabs.setup();
TabHost.TabSpec spec = tabs.newTabSpec("tag 1");
spec.setContent(R.id.tab1);
spec.setIndicator("Clock");
tabs.addTab(spec);
spec = tabs.newTabSpec("tag2");
spec.setContent(R.id.tab2);
spec.setIndicator("Button");
tabs.addTab(spec);
tabs.setCurrentTab(0);
}
}
grazie a tutti in anticipo
-
Nell'XML puoi togliere il LinearLayout che non ha senso:
XML:
Nel java prova con:
Buon lavoro :)
-
grazie mille =)
dunque provando il tuo codice mi da errori relativi al tabHost, più precisamente:
tabHost cannot be resolved or is not a field
ho dato l'esame di java lo scorso anno ed ora sono un pò arrugginito :P tabHost è dichiarata poco più su, perchè non può essere risolta?
-
Togli il this all'ultima riga.
Inviato dal mio Nexus S usando Tapatalk
-
togliendo tutti i this compila ( mamma mia, m'ero completamente scordato l'uso del this dopo un anno a C e basta roftl ), però non risolve il problema del crash all'avvio
-
l'output di logcat sarebbe di aiuto
-
Scusate per l'assenza ma ho avuto un fine settimana impegnato, copio tutto l'output del logcat, comunque l'errore dovrebbe essere "java.lang.RuntimeException: Your TabHost must have a TabWidget whose id attribute is 'android.R.id.tabs' "
codice:
06-06 16:09:01.465: INFO/ActivityManager(58): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=prova.TabDemo/.TabDemo }
06-06 16:09:01.725: INFO/ActivityManager(58): Start proc prova.TabDemo for activity prova.TabDemo/.TabDemo: pid=283 uid=10036 gids={1015}
06-06 16:09:02.875: DEBUG/AndroidRuntime(283): Shutting down VM
06-06 16:09:02.875: WARN/dalvikvm(283): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
06-06 16:09:02.895: ERROR/AndroidRuntime(283): FATAL EXCEPTION: main
06-06 16:09:02.895: ERROR/AndroidRuntime(283): java.lang.RuntimeException: Unable to start activity ComponentInfo{prova.TabDemo/prova.TabDemo.TabDemo}: java.lang.RuntimeException: Your TabHost must have a TabWidget whose id attribute is 'android.R.id.tabs'
06-06 16:09:02.895: ERROR/AndroidRuntime(283): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
06-06 16:09:02.895: ERROR/AndroidRuntime(283): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
06-06 16:09:02.895: ERROR/AndroidRuntime(283): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
06-06 16:09:02.895: ERROR/AndroidRuntime(283): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
06-06 16:09:02.895: ERROR/AndroidRuntime(283): at android.os.Handler.dispatchMessage(Handler.java:99)
06-06 16:09:02.895: ERROR/AndroidRuntime(283): at android.os.Looper.loop(Looper.java:123)
06-06 16:09:02.895: ERROR/AndroidRuntime(283): at android.app.ActivityThread.main(ActivityThread.java:4627)
06-06 16:09:02.895: ERROR/AndroidRuntime(283): at java.lang.reflect.Method.invokeNative(Native Method)
06-06 16:09:02.895: ERROR/AndroidRuntime(283): at java.lang.reflect.Method.invoke(Method.java:521)
06-06 16:09:02.895: ERROR/AndroidRuntime(283): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
06-06 16:09:02.895: ERROR/AndroidRuntime(283): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
06-06 16:09:02.895: ERROR/AndroidRuntime(283): at dalvik.system.NativeStart.main(Native Method)
06-06 16:09:02.895: ERROR/AndroidRuntime(283): Caused by: java.lang.RuntimeException: Your TabHost must have a TabWidget whose id attribute is 'android.R.id.tabs'
06-06 16:09:02.895: ERROR/AndroidRuntime(283): at android.widget.TabHost.setup(TabHost.java:103)
06-06 16:09:02.895: ERROR/AndroidRuntime(283): at prova.TabDemo.TabDemo.onCreate(TabDemo.java:15)
06-06 16:09:02.895: ERROR/AndroidRuntime(283): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-06 16:09:02.895: ERROR/AndroidRuntime(283): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
06-06 16:09:02.895: ERROR/AndroidRuntime(283): ... 11 more
06-06 16:09:02.905: WARN/ActivityManager(58): Force finishing activity prova.TabDemo/.TabDemo
06-06 16:09:03.415: WARN/ActivityManager(58): Activity pause timeout for HistoryRecord{4509efc0 prova.TabDemo/.TabDemo}
-
devi usare gli infilater x definire le viste...
dove R.layout.viewxml è il file xml dove hai definito il layout del primo tab, e R.id.view è l'id del layout da includere definito dentro a R.layout.viewxml.xml e con il toggle ...
stessa cosa è la spiegazione per il secondo tab...
-
grazie per la risposta, ma è una discussione di 5 mesi fa, se non avevo risolto m'ero sparato rotflrotfl