在tabhost android中的活动?

问题描述:

我想要标签中的不同活动这里是我写的代码,但应用程序不断崩溃这里发生了什么?在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

您需要了解如何在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报告,请帮助我,如果可能的话,谢谢! –