Android TabWidget NullpointerException?
我试图创建一个包含两个选项卡的选项卡小部件来打开两个不同的活动,并编写以下布局来实现这一点,但它给了我一个NullPointerException 我的错在哪里Android TabWidget NullpointerException?,android,tabwidget,Android,Tabwidget,我试图创建一个包含两个选项卡的选项卡小部件来打开两个不同的活动,并编写以下布局来实现这一点,但它给了我一个NullPointerException 我的错在哪里 <?xml version="1.0" encoding="utf-8"?> <TabHost xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/tabhost" android:layout_w
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget
android:id="@android: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">
</FrameLayout>
</LinearLayout>
</TabHost>
如果要使用TabActivity扩展tab类,则必须使用它 使用选项卡相关控件的id,如@android:id/tabhost 我使用了@+id/tabhost,这是错误的,但在通过活动类扩展它的情况下,这很好 我在布局上遇到的上述问题不会出现 Tab教程也有点问题,可以使用以下示例解决。
在Eclipse中使用adb logcat、DDMS或DDMS透视图检查堆栈跟踪,它将告诉您问题所在。02-18 11:08:01.197:INFO/ActivityManager 52:Starting activity:Intent{cmp=com.example.FindItNear/.More}02-18 11:08:11.224:WARN/ActivityManager 52:Launch timeout已过期,放弃唤醒锁!02-18 11:08:11.368:WARN/ActivityManager 52:HistoryRecord的活动空闲超时{43dba948 com.example.FindItNear/.More}将您的评论作为编辑添加到帖子中,以便对其进行格式化,从而使其更易于阅读。那么,您是否修复了它?
setContentView(R.layout.more);
TabHost mTabHost = (TabHost) this.findViewById(R.id.tabhost);
mTabHost.setup();
Intent intent;
intent = new Intent().setClass(this, Settings.class);
mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator(
"Calculator",
getResources().getDrawable(R.drawable.tab01)).setContent(intent));
intent = new Intent().setClass(this, Post.class);
mTabHost.addTab(mTabHost.newTabSpec("tab_test2").setIndicator(
"YouTube",
getResources().getDrawable(R.drawable.tab02)).setContent(intent));