2010-02-17 60 views
1

我想創建一個標籤小部件與兩個選項卡來打開兩個不同的活動,並編寫以下佈局來實現這一目標,但它給了我一個NullPointerExceptionTabWidget 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)); 
+1

在Eclipse中使用'adb logcat',DDMS或DDMS透視圖來檢查堆棧跟蹤,它會告訴你問題出在哪裏。 – CommonsWare 2010-02-17 16:00:21

+0

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

+0

添加您的評論作爲對帖子的修改(以便它可以格式化因此更容易閱讀) – KevinDTimm 2010-02-18 11:54:08

回答

-1
如果你正在使用TabActivity延長你的標籤類

那麼必須

使用類似「@android:id/tabhost」這樣的標籤相關控件的ID

我在使用「@ + id/tabhost」,這是錯誤的,但在延長它通過Activity類的情況下它的罰款。

以上,我面臨的佈局不會來的問題......

標籤教程也有點馬車它可以使用下面的例子來解決。 Example

+0

因此,你有沒有修復它? – KevinDTimm 2010-02-18 11:59:02

+0

現在修好了.. – UMAR 2010-02-22 14:30:51

0

沒有太多的信息在這裏繼續下去,但檢查我的問題(和它的答案)爲一個潛在的解決方案
Issues with Android TabHost Example

+0

我已經糾正了這些問題..但問題是在我的佈局文件中..我剛纔複製了Android中的Tabactivity示例中提到的佈局代碼...仍然沒有希望.. – UMAR 2010-02-18 06:09:46