Frage

Ich bin derzeit eine Anwendung für Android zu entwickeln, die eine maßgeschneiderte Tabs verwenden muss. Ich habe zwei Probleme:

Ich werde von meinem ersten Problem starten:

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)
...

Ich erhalte diese Ausnahme, wenn ich von einem Textmodus wyswig Modus in Eclipse wechseln möchten. Dies ist die eigentliche XML-Code, der mir diesen Fehler gibt:

<?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>

Jetzt das zweite Problem ist ein Grafik-Artefakt: http://img529.imageshack.us/img529/8216/99725485.png

Wie kann ich meine Probleme lösen?

War es hilfreich?

Lösung 2

Ich habe fix geschaffen, was ich war, obwohl ein visuell-Artefakt:

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

Auch scheint es, dass, wenn ich TabHost und TabWidget in meinen Projekten verwende ich bin diese Ausnahme immer, auch ich es auf Android-Tutorials überprüft haben: http://developer.android.com/resources/tutorials/views/hello-tabwidget.html und ja, ich habe es auch bekam

Andere Tipps

Es ist ziemlich offensichtlich, was falsch ist und auch die Botschaft in Eclipse sagt Ihnen ganz genau, was der Fehler ist. Ihre FrameLayout hat keinen Inhalt.

Was wollen Sie mit diesem FrameLayout erreichen?

UPDATE: Just realisiert, was Sie tun wollten. Versuchen Sie, dieses Layout.

<?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>

Ich habe korrigiert auch einen weiteren Fehler für Sie. Eigentlich nicht unbedingt ein Fehler, aber immer noch. Im RadioGroup zuweisen Sie den ersten RadioButton die ID first mit android:checkedButton="@+id/first", wenn Sie es sind verweisen. Wenn Sie tatsächlich auf die RadioButton Ihre ID-Definition erhalten sollte kein + mehr enthalten. Schauen Sie sich das Layout.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top