【解决】Element type "typename" must be followed by either attribute specifications, ">" or "/>".

问题

昨天学习Android的几种布局,敲代码时遇到这样的报错:Element type "TableRow" must be followed by either attribute specifications, ">" or "/>".

【解决】Element type "typename" must be followed by either attribute specifications, ">" or "/>"._第1张图片

解决

根据报错的提示,在<TableRow后面加上一个>   

如果还没有反应,ctrl+s保存一下。我用ADT敲代码时,编译器一般都会有些这样的“迟钝”。(再次感到对比之下AndroidStudio好用得催人泪下 T 。T)

【解决】Element type "typename" must be followed by either attribute specifications, ">" or "/>"._第2张图片


原因是我在图形界面拖进一个TableLayout后,ADT会自动在相应的XML文件中添加如下代码。自动添加了四个TableRow,而我用不到这么多,所以删掉了三个,同时删掉了TableRow的属性设置,这样就删掉了android:layout_height="wrap_content" > 这一行中的 >   ,因此报错。

一个细节导致的错误。

<TableLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >

                <TableRow
                    android:id="@+id/tableRow1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" >
                </TableRow>

                <TableRow
                    android:id="@+id/tableRow2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" >
                </TableRow>

                <TableRow
                    android:id="@+id/tableRow3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" >
                </TableRow>

                <TableRow
                    android:id="@+id/tableRow4"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" >
                </TableRow>
            </TableLayout>

收获

Android布局文件的XML中, 可作为容器的组件(以TableLayout为例),格式一般是这样的:
<pre name="code" class="html">

<TableLayout
      <!-- 此TableLayout的一些属性设置   -->     
      >
        
	<span style="white-space:pre">	</span><!-- 添加的一些组件 -->
		
         
</TableLayout>

你可能感兴趣的:(android,布局,XML格式)