简体   繁体   English

android.content.res.Resources $ NotFoundException:来自xml类型布局资源ID的文件#0x1020014

[英]android.content.res.Resources$NotFoundException: File from xml type layout resource ID #0x1020014

I'm trying to use an ArrayAdapter in a ListActivity: 我正在尝试在ListActivity中使用ArrayAdapter:

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.id.text1, new String[] { "a", "b"});
setListAdapter(adapter);

This is the layout: 这是布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView
        android:id="@id/android:text1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10" />

    <ListView
        android:id="@id/android:list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="false"
        android:layout_below="@id/android:text1" >

    </ListView>

</RelativeLayout>

None of the solutions I found on StackOverflow seems to work. 我在StackOverflow上找到的解决方案似乎都不起作用。 I'm using API 10. Can you help please? 我正在使用API​​ 10.你能帮帮忙吗?

You are using the wrong type of resource, you need to reference R.layout not R.id . 您使用的是错误类型的资源,需要引用R.layout而不是R.id Try android.R.layout.simple_list_item_1 : 试试android.R.layout.simple_list_item_1

new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, new String[] { "a", "b"});

Define a layout for the rows of your ListView, and call it, for example, simple_list_item_1 (create the file simple_list_item_1.xml in the folder res/layout ). 为ListView的行定义布局,并调用它,例如, simple_list_item_1 (在文件夹res/layout创建文件simple_list_item_1.xml )。 Put your TextView into this layout: TextView放入此布局:

<?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" >
    <TextView
        android:id="@id/android:text1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10" />
</RelativeLayout>

and then create your ArrayAdapter like this: 然后像这样创建ArrayAdapter:

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.simple_list_item_1, R.id.text1, new String[] { "a", "b"});

Here you'll find a detailed explanation about Lists and Adapters. 在这里,您将找到有关列表和适配器的详细说明。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 android.content.res.Resources $ NotFoundException:来自xml类型布局资源ID#0x109001b的文件res / layout / action_menu_layout.xml - android.content.res.Resources$NotFoundException: File res/layout/action_menu_layout.xml from xml type layout resource ID #0x109001b android.content.res.Resources $ NotFoundException:资源ID#0x0 - android.content.res.Resources$NotFoundException: Resource ID #0x0 android.content.res.Resources$NotFoundException:资源 ID #0x7f070016 类型 #0x3 无效 - android.content.res.Resources$NotFoundException: Resource ID #0x7f070016 type #0x3 is not valid android.content.res.Resources$NotFoundException · 字符串资源 ID # - android.content.res.Resources$NotFoundException · String resource ID # android.content.res.Resources $ NotFoundException:无法找到资源ID - android.content.res.Resources$NotFoundException: Unable to find resource ID GridView.FATAL例外:main android.content.res.Resources $ NotFoundException:字符串资源ID#0x0 - GridView.FATAL EXCEPTION: main android.content.res.Resources$NotFoundException: String resource ID #0x0 android.content.res.Resources $ NotFoundException:资源ID#0x88a6fd - android.content.res.Resources$NotFoundException: Resource ID #0x88a6fd android.content.res.Resources$NotFoundException:使用 RecyclerView 时出现资源 ID #0x0 异常 - android.content.res.Resources$NotFoundException: Resource ID #0x0 exception while using RecyclerView android.content.res.Resources $ NotFoundException:字符串资源ID#0x2 - android.content.res.Resources$NotFoundException: String resource ID #0x2 android.content.res.Resources$NotFoundException: 字符串资源 ID #0x0 - android.content.res.Resources$NotFoundException: String resource ID #0x0
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM