2010-11-19 10 views
1

私は現在、カスタムメイドのタブを使用する必要があるAndroid用アプリケーションを開発しています。androidとvisual-artifactのためのeclipseのwyswig xmlレイアウトのnullpointerexception

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

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するには、テキストモードから切り替えたいとき、私はこの例外を取得しています私は2つの問題に遭遇しました。 これは私にそのエラーを与える実際の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> 

今、第二の問題は、グラフィック・アーティファクトです: http://img529.imageshack.us/img529/8216/99725485.png

どのように私は私の問題を解決することができますか?

答えて

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を使用するたびに、私はそれをチェックしても、その例外を取得していているようですアンドロイドチュートリアル:http://developer.android.com/resources/tutorials/views/hello-tabwidget.html はい、私もそれを持っています

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> 

また、間違いを修正しました。実際には必ずしも間違いではありません。 RadioGroupでは、最初にRadioButtonというIDを参照するときにandroid:checkedButton="@+id/first"と割り当てています。実際にRadioButtonにアクセスすると、ID定義にはもう+が含まれてはなりません。レイアウトをチェックしてください。

関連する問題