2011-11-30 62 views
1

我想要標籤中的不同活動這裏是我寫的代碼,但應用程序不斷崩潰這裏發生了什麼?在tabhost android中的活動?

TabHost th = (TabHost)findViewById(R.id.tabhost); 
    th.setup(); 

TabSpec specs1 = th.newTabSpec("tag2"); 

    specs1.setIndicator("Tab 2"); 
    specs1.setContent(new Intent(this, Songs.class)); 
    th.addTab(specs1); 

任何幫助,將appritated感謝ü

編輯

這是我得到的logcat

11-29 23:23:06.490: D/AndroidRuntime(299): Shutting down VM 
11-29 23:23:06.490: W/dalvikvm(299): threadid=1: thread exiting with uncaught exception (group=0x4001d800) 
11-29 23:23:06.510: E/AndroidRuntime(299): FATAL EXCEPTION: main 
11-29 23:23:06.510: E/AndroidRuntime(299): java.lang.IllegalStateException: Did you forget to call 'public void setup(LocalActivityManager activityGroup)'? 
11-29 23:23:06.510: E/AndroidRuntime(299):  at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:649) 
11-29 23:23:06.510: E/AndroidRuntime(299):  at android.widget.TabHost.setCurrentTab(TabHost.java:323) 
11-29 23:23:06.510: E/AndroidRuntime(299): at android.widget.TabHost$2.onTabSelectionChanged(TabHost.java:129) 
11-29 23:23:06.510: E/AndroidRuntime(299): at android.widget.TabWidget$TabClickListener.onClick(TabWidget.java:453) 
11-29 23:23:06.510: E/AndroidRuntime(299): at android.view.View.performClick(View.java:2408) 
11-29 23:23:06.510: E/AndroidRuntime(299): at android.view.View$PerformClick.run(View.java:8816) 
11-29 23:23:06.510: E/AndroidRuntime(299):  at android.os.Handler.handleCallback(Handler.java:587) 
11-29 23:23:06.510: E/AndroidRuntime(299):  at android.os.Handler.dispatchMessage(Handler.java:92) 
11-29 23:23:06.510: E/AndroidRuntime(299):  at android.os.Looper.loop(Looper.java:123) 
11-29 23:23:06.510: E/AndroidRuntime(299):  at android.app.ActivityThread.main(ActivityThread.java:4627) 
11-29 23:23:06.510: E/AndroidRuntime(299): at java.lang.reflect.Method.invokeNative(Native Method) 
11-29 23:23:06.510: E/AndroidRuntime(299): at java.lang.reflect.Method.invoke(Method.java:521) 
11-29 23:23:06.510: E/AndroidRuntime(299): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 
11-29 23:23:06.510: E/AndroidRuntime(299): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 

11-29 23:23:06.510:E/AndroidRuntime( 299):在dalvik.system.NativeStart.main(本地方法)

+0

發表您的logcat.and確保您延長TabActivity並不僅僅是活動! – Hiral

+0

你有沒有在清單文件中註冊Activity? –

+0

我想你必須使用TabHost th = getTabHost(); – Newts

回答

1

您需要了解如何在Eclipse中進行調試以及如何使用ADBDDMS工具。

爲了獲得有關異常/力更多的細節接近,你需要尋找在Eclipse視圖稱爲Logcat(你會發現在DDMS觀點)那裏,你會發現一個詳細的追蹤時,/什麼,在哪一行是問題。

爲此,您應該閱讀完整文章約Debugging in Android using Eclipse

alt text http://www.droidnova.com/blog/wp-content/uploads/2009/09/debugging-3.gif

+2

這不是一個答案。這是對如何更好地發現問題的評論。 –

+0

我已經把logcat報告,請幫助我,如果可能的話,謝謝! –