diadia

興味があることをやってみる。自分のメモを残しておきます。

レイアウトファイルのエラー原因

LinearLayout

自分がよく起こすレイアウトファイルのエラーはLinearLayoutに/をつけることが問題であった。

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

省略


</LinearLayout>

これが正しい書き方であるが、最初のタグに"/>"を書くとエラーが出てしまう。

TextViewやImageView等

TextViewやImageViewなどの閉じタグが必要ない一つで完結するタグにおいては、"/>"にするのが正しい記法である。
一方で"/"無しでタグを閉じるとエラーが出てしまうので注意すること。

Multiple root tags エラー

参考:https://teratail.com/questions/45822

レイアウトファイルの構成ではルートになるタグが複数あってはいけないようだ。これはxmlの決まりなのかもしれない。
https://stackoverflow.com/questions/5042902/xml-error-there-are-multiple-root-elements