0

ねえ...次のようなレイアウト構造でアクティビティを作成しようとしています:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >

    <TabHost 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:layout_width="fill_parent"
                android:layout_height="wrap_content" 
                android:id="@android:id/tabs" 
                /> 
            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                >
            </FrameLayout>
        </LinearLayout>
     </TabHost>

     <some code here>

</LinearLayout>

ここで何が問題なのですか?アクティビティで nullPointerException が発生しています

public class TabsActivity extends Activity
{
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tabs);

        // Resources res = getResources();
        // TabHost tabHost = (TabHost)findViewById(R.id.tabHost);
   }
}

問題はネスティングにあります。TabHost をメインの XML ノードとして使用しても問題ありません。どうも!

エラー: スクリーンショット

4

2 に答える 2

0

スタック トレースを誤解しています。

内部で例外が発生していIntentます。アクティビティのIntent開始に使用している は無効です。を修正すればIntent、問題は解決します。

于 2010-09-19T12:09:44.967 に答える
0

同様の問題がありましたが、解決策は を取得してTabHostを呼び出すことでしたsetup()。それがあなたの問題かどうかはわかりません。

于 2010-09-23T20:30:24.207 に答える