Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在android应用程序中获取消息:二进制XML文件行#2:必须提供布局宽度属性_Java_Android - Fatal编程技术网

Java 在android应用程序中获取消息:二进制XML文件行#2:必须提供布局宽度属性

Java 在android应用程序中获取消息:二进制XML文件行#2:必须提供布局宽度属性,java,android,Java,Android,我试图在RelativeLayout中使用ListView,但当我运行我的应用程序时,我收到一个runtimeexception,其中包含以下消息: 二进制XML文件第2行:必须提供布局宽度属性 我试着将layout_width属性放在xml资源文件中每个可能的位置,但到目前为止没有成功 我尝试使用以下代码行填充listview: .setListAdapter(new ArrayAdapter(this, R.layout.tablerow3, R.id.label

我试图在RelativeLayout中使用ListView,但当我运行我的应用程序时,我收到一个runtimeexception,其中包含以下消息:

二进制XML文件第2行:必须提供布局宽度属性

我试着将layout_width属性放在xml资源文件中每个可能的位置,但到目前为止没有成功

我尝试使用以下代码行填充listview:

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

android:layout_width=“20dp”
android:layout_height=“5dp”
android:id=“@+id/tablerow01”>
以下是包含RelativeLayout(forex2.xml)的xml:


错误在这里:

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

android:layout_width=“20dp”
android:layout_height=“5dp”
android:id=“@+id/tablerow01”>

查看以LinearLayout开头的行的末尾。您留下了一个>关闭标记,这意味着后面的属性被XML解析器视为文本块,即LinearLayout标记的子项。只需删除多余的>,您就可以了。

关于您的评论,没有Android小部件作为标签。您可能需要一个文本视图。

这不是您的特定问题的答案,而是导致相同错误的另一个原因

我有一个类似的错误,唯一的问题是我输入了模式,而不是模式


希望这对其他人有帮助。

谢谢-真不敢相信我错过了。现在,我将看到下一条错误消息:二进制XML文件行#6:错误膨胀类标签。
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android">
      android:layout_width="20dp"
      android:layout_height="5dp"
      android:id="@+id/tablerow01">
LinearLayout xmlns:android="http://schema.android.com/apk/res/android" // wrong

LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" // correct.