1

私は現在、カスタムメイドのタブを使用する必要があるAndroid用のアプリケーションを開発しています。私は2つの問題に遭遇しました:

私は私の最初の問題から始めます:

java.lang.NullPointerException
at android.widget.TabWidget.initTabWidget(TabWidget.java:115)
at android.widget.TabWidget.<init>(TabWidget.java:86)
at android.widget.TabWidget.<init>(TabWidget.java:69)
...

Eclipseでテキストモードからwyswigモードに切り替えたいときに、この例外が発生します。これは私にそのエラーを与える実際のxmlコードです:

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android: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">

       <FrameLayout android:id="@android:id/tabcontent"
           android:layout_width="fill_parent"
           android:layout_height="0dip"
           android:layout_weight="1"
           android:padding="20dip"
           android:background="#fff" />

       <RadioGroup android:layout_width="fill_parent"
           android:layout_height="wrap_content"
           android:orientation="horizontal"
           android:checkedButton="@+id/first"
           android:id="@+id/states">
           <RadioButton android:id="@+id/first"
               android:background="#FF00FF"
               android:width="80dip"
               android:height="70dip" />
           <RadioButton android:id="@+id/second"
               android:background="#FFFFFF"
               android:width="80dip"
               android:height="70dip" />
           <RadioButton android:id="@+id/third"
               android:background="#00FFFF"
               android:width="80dip"
               android:height="70dip" />
           <RadioButton android:id="@+id/fourth"
               android:background="#0000FF"
               android:width="80dip"
               android:height="70dip" />
       </RadioGroup>

      <TabWidget android:id="@android:id/tabs"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_weight="0"
          android:visibility="gone" />  
    </LinearLayout>
</TabHost>

次に、2番目の問題はグラフィックアーティファクトです。 http://img529.imageshack.us/img529/8216/99725485.png

どうすれば問題を解決できますか?

4

2 に答える 2

0

何が間違っているかはかなり明白であり、Eclipseのメッセージは間違いが何であるかを正確に示しています。あなたFrameLayoutにはコンテンツがありません。

それで何を達成しようとしていFrameLayoutますか?

更新:あなたがやろうとしていたことに気づきました。このレイアウトを試してください。

<?xml version="1.0" encoding="utf-8"?>
<TabHost
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android: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">
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="0dip"
            android:layout_weight="1"
            android:padding="20dip"
            android:background="#fff">
            <RadioGroup
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:checkedButton="@+id/first"
                android:id="@+id/states">
                <RadioButton
                    android:id="@id/first"
                    android:background="#FF00FF"
                    android:width="80dip"
                    android:height="70dip"/>
                <RadioButton
                    android:id="@+id/second"
                    android:background="#FFFFFF"
                    android:width="80dip"
                    android:height="70dip"/>
                <RadioButton
                    android:id="@+id/third"
                    android:background="#00FFFF"
                    android:width="80dip"
                    android:height="70dip"/>
                <RadioButton
                    android:id="@+id/fourth"
                    android:background="#0000FF"
                    android:width="80dip"
                    android:height="70dip"/>
            </RadioGroup>
        </FrameLayout>
        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0"
            android:visibility="gone"/>
    </LinearLayout>
</TabHost>

私はあなたのために別の間違いも訂正しました。実際には必ずしも間違いではありませんが、それでも。で、参照するときに最初にIDをRadioGroup割り当てます。あなたが実際にあなたのIDに到達したとき、あなたのID定義はもう含まれるべきではありません。レイアウトを確認してください。RadioButtonfirstandroid:checkedButton="@+id/first"RadioButton+

于 2010-11-19T22:30:19.327 に答える
0

私は視覚的なアーティファクトでしたが、なんとか修正できました:

<FrameLayout android:id="@android:id/tabcontent"
        android:layout_width="fill_parent" android:layout_height="fill_parent"
        android:layout_weight="1" android:background="#FFFFFF" />

また、プロジェクトでTabHostとTabWidgetを使用すると、その例外が発生するようです。また、Androidチュートリアルで確認したようです:http://developer.android.com/resources/tutorials/views/hello-tabwidget.html はい、私も持っています

于 2010-11-19T22:52:01.353 に答える