【问题标题】:Resources$NotFoundException: Resource ID # type #0x12 is not validResources$NotFoundException: 资源 ID # 类型 #0x12 无效
【发布时间】:2017-01-20 12:26:19
【问题描述】:

请告诉我,为什么它不喜欢我的布局(RelativeLayout with @+id/row)?

当我将它与自行创建的适配器 (layoutinflater) 一起使用时,效果很好。 还有一个。我计划在我的数据库中使用位图,存储为byte[]SimpleCursorAdapter 本身可以将 byte[] 日期转换为图像(ImageView)还是仅适用于文本?

错误说明

android.content.res.Resources$NotFoundException: Resource ID #0x7f0c006c type #0x12 is not valid

MainActivity

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mListView = ( (ListView) findViewById (R.id.notes_listView) );
    mNoteDb = new NoteDb (getApplicationContext ());
    Cursor c = mNoteDb.getTitleColumn ();

    SimpleCursorAdapter mAdapter = new SimpleCursorAdapter (getApplicationContext (),
            R.id.row, // **<<< THIS ONE**
            c, new String[]{NoteDb.MainTable.COLUMN_TITLE}, new int[]{R.id.title_text_row}, 0);
    mListView.setAdapter (mAdapter);

行布局

<RelativeLayout
android:id="@+id/row"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
    android:id="@+id/date_row"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_marginRight="10sp"
    android:text="@string/main_row_tv_date"
    android:textSize="14sp"/>

<ImageView
    android:id="@+id/note_icon"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:contentDescription="@string/main_row_icon_description"
    android:cropToPadding="true"
    android:maxHeight="45dp"
    android:maxWidth="45dp"
    android:adjustViewBounds="true"
    app:srcCompat="@mipmap/ic_launcher"
    android:layout_alignBottom="@+id/priority_icon"/>

<ImageView
    android:id="@+id/priority_icon"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentEnd="true"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/date_row"
    android:contentDescription="@string/main_row_icon_priority_description"
    android:maxHeight="25dp"
    android:maxWidth="25dp"
    android:cropToPadding="true"
    android:src="@drawable/ic_priority_first"
    android:adjustViewBounds="true"/>

<TextView
    android:id="@+id/title_text_row"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="20sp"
    android:layout_alignBottom="@id/note_icon"
    android:layout_toRightOf="@+id/note_icon"
    android:layout_toEndOf="@+id/note_icon"
    android:text="@string/main_row_tv_title"/>

光标查询

public Cursor getTitleColumn () {
    SQLiteDatabase db;
    db = mNoteDbOpenHelper.getReadableDatabase ();
    Cursor c = db.query (MainTable.TABLE_NAME,
            new String[] {MainTable._ID, MainTable.COLUMN_TITLE},
            null, null, null, null, null);
    return c;

【问题讨论】:

    标签: android listview simplecursoradapter


    【解决方案1】:

    您应该提供布局而不是 id。将R.id.row 替换为R.layout.your_layout_name

    【讨论】:

      【解决方案2】:

      我真的打赌你想在某个地方textView.setText(Integer)

      韩,没有完整阅读问题。更新

      不,您不能在默认适配器中放置图片。它仅适用于文本。您需要创建自己的Adapter。我建议你切换到RecyclerView 尤其是显示图片,

      【讨论】:

        猜你喜欢
        • 2020-02-02
        • 1970-01-01
        • 1970-01-01
        • 2022-09-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多