Resources$NotFoundException: Resource ID # type #0x12 is not valid

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-30 18:06:54

问题


Tell me please, why it doesn't like my layout (RelativeLayout with @+id/row)?

When I use it with self created adapter (layoutinflater) it works good. And one more. I plan to use in my database bitmaps, stored like byte[]. Can SimpleCursorAdapter itself convert byte[] dates in to image (ImageView) or does it work only with texts?

Error description

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);

row layout

<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"/>

Cursor query

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;

回答1:


you should provide a layout not an id. Replace R.id.row with R.layout.your_layout_name




回答2:


I really bet you trying to textView.setText(Integer) somewhere.

Han, didn't read question fully. Update

No, you can't place pictures in default adapter. It works only with text. You need to create your own Adapter. And I recommend you to switch to RecyclerView especially with displaying pictures,



来源:https://stackoverflow.com/questions/41763675/resourcesnotfoundexception-resource-id-type-0x12-is-not-valid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!