2011-01-12 3 views
2

私はRelativeLayout内でListViewを使用しようとしていますが、私のアプリを実行するときにメッセージでruntimeexceptionを取得します:android appでメッセージを取得する:2進数のXMLファイルライン#2:layout_width属性を指定する必要があります

バイナリXMLファイル行#2:layout_width属性を指定する必要があります。

私はlayout_width属性をxmlリソースファイル内の考えられるすべての場所に配置しようとしましたが、これまでの運はありませんでした。

私はこのコード行でリストビューを移入しようとすると:

.setListAdapter(new ArrayAdapter(this, 
      R.layout.tablerow3, R.id.label, 
      items)); 

ここtablerow3.xml内容だ:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"> 
    android:layout_width="20dp" 
    android:layout_height="5dp" 
    android:id="@+id/tablerow01"> 

    <Label android:id="@+id/label01" 
     android:layout_width="5dp" 
     android:layout_height="5dp" 
     android:textColor="@color/solid_white" 
     android:singleLine="true"/> 

    <Label android:id="@+id/label02" 
     android:layout_width="5dp" 
     android:layout_height="5dp" 
     android:textColor="@color/solid_white" 
     android:singleLine="true"/> 
</LinearLayout> 

ここRelativeLayout(forex2.xml)を含むXMLです:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <Button android:text="Static Button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:id="@+id/button_id"> 
    </Button> 

    <Spinner android:id="@+id/spinner1" 
     android:layout_width="match_parent" 
     android:layout_toRightOf="@id/button_id" 
     android:layout_alignParentTop="true" 
     android:layout_height="wrap_content" 
     android:drawSelectorOnTop="true" 
    /> 

    <ListView android:id="@android:id/list" 
     android:layout_width="5dp" 
     android:layout_height="5dp" 
     android:layout_alignParentBottom="true" 
    /> 
    <!-- android:layout_width="wrap_content" 
     android:layout_height="wrap_content" --> 
</RelativeLayout> 

答えて

4

バグはここにある:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"> 
     android:layout_width="20dp" 
     android:layout_height="5dp" 
     android:id="@+id/tablerow01"> 

LinearLayoutで始まる行の最後を見てください。 >を残してタグを閉じます。これは、XMLパーサーがLinearLayoutタグの子であるテキストブロックとして扱うことを意味します。余分なものを取り除くだけで、あなたは大丈夫でしょう。

+0

ありがとう - 私はそれを逃したと信じられない。 次のエラーメッセージが表示されます。バイナリXMLファイルの行番号6:クラスを拡張する際にエラーが発生しました。 – opike

1

あなたのコメントに関して、ラベルのAndroidウィジェットはありません。代わりにTextViewが必要になるでしょう。

1

これはあなたの特定の問題に対する答えではなく、同じエラーの別の原因です。

私は、同様のエラーを持っていた、唯一の私の問題は、私が

すなわちをするスキーマというし、スキーマに入ったということでした。

これが他の人に役立つと願っています。

関連する問題