java.lang.UnsupportedOperationException运行时错误
我正在开发一个QR阅读器应用程序。在这个类中,我实现了在用户扫描二维码时将数据输入列表视图。当我运行它时,它会给出不支持的操作异常。我在这里发布代码和日志。提前感谢:) XML文件java.lang.UnsupportedOperationException运行时错误,java,android,exception,Java,Android,Exception,我正在开发一个QR阅读器应用程序。在这个类中,我实现了在用户扫描二维码时将数据输入列表视图。当我运行它时,它会给出不支持的操作异常。我在这里发布代码和日志。提前感谢:) XML文件 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertica
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/linLayout1">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/QRButton"
android:text="QR Scan"
android:textSize="18sp"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ExitButton"
android:text="Back Main"
android:textSize="18sp"/>
</LinearLayout>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/statusText"
android:layout_below="@+id/linLayout1"
android:text="Press QR Scan Button to Scan Items"
android:textSize="18sp"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/resultText"
android:text="Ready to Scan"
android:textSize="18sp"
android:layout_below="@+id/statusText"
android:background="@android:color/white"
android:textColor="@android:color/black"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/qrItmList">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/text1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/text2"/>
</ListView>
</LinearLayout>
</RelativeLayout>
您的问题在于:
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/qrItmList">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/text1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/text2"/>
</ListView>
ListView
不能以这种方式声明子级。您可以通过适配器
填充列表视图
(在您的例子中,是simpledapter
)。删除这两个TextView
小部件,或将它们移到布局中的其他位置。请发布R.layout.qrscannermenu
的布局,因为您的问题就在那里。@Commonware ok添加了它!!你能告诉我SimpleAdapter的代码应该是什么吗。。因为我是Android编程新手。。非常感谢。@MiurangaSalgado:在安卓7年的开发过程中,我不记得曾经使用过simpledapter
。但是,您已经有了它的代码。只需从布局的列表视图
中删除两个文本视图
小部件,然后试着运行项目。啊,好的,我试试看:)它现在给出的结果如下图所示。。打印整个版面。。我能为此做些什么???@Miuragasalgado:因为我不是在写你的应用程序,所以我真的无法回答这个问题。使用层次视图可以查看布局规则的解释方式。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/linLayout1">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/QRButton"
android:text="QR Scan"
android:textSize="18sp"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ExitButton"
android:text="Back Main"
android:textSize="18sp"/>
</LinearLayout>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/statusText"
android:layout_below="@+id/linLayout1"
android:text="Press QR Scan Button to Scan Items"
android:textSize="18sp"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/resultText"
android:text="Ready to Scan"
android:textSize="18sp"
android:layout_below="@+id/statusText"
android:background="@android:color/white"
android:textColor="@android:color/black"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/qrItmList">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/text1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/text2"/>
</ListView>
</LinearLayout>
</RelativeLayout>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/qrItmList">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/text1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/text2"/>
</ListView>