我想創建一個標籤小部件與兩個選項卡來打開兩個不同的活動,並編寫以下佈局來實現這一目標,但它給了我一個NullPointerException
。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_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>
其中延長TabWidget
的Java類我在onCreate
方法如下代碼:
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));
在Eclipse中使用'adb logcat',DDMS或DDMS透視圖來檢查堆棧跟蹤,它會告訴你問題出在哪裏。 – CommonsWare 2010-02-17 16:00:21
02-18 11:08:01.197:INFO/ActivityManager(52):開始活動:意圖{cmp = com.example.FindItNear/.More} 02-18 11:08:11.224:WARN/ActivityManager(52)啓動超時已過,放棄喚醒鎖定! 02-18 11:08:11.368:WARN/ActivityManager(52):HistoryRecord的活動閒置超時{43dba948 com.example.FindItNear/.More} – UMAR 2010-02-18 06:07:14
添加您的評論作爲對帖子的修改(以便它可以格式化因此更容易閱讀) – KevinDTimm 2010-02-18 11:54:08