Android finds resource by id at runtime

If I get the error "android.content.res.Resources $ NotFoundException: Resource ID # 0x7f050007 of type # 0x12 is invalid" can I find some resource if I know its ID?

        ListView list = (ListView)findViewById(R.id.messages_list_view);
        list.setAdapter(new ArrayAdapter<String>(context,
        R.layout.messages_list, headers));

messages_list.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/messages_list_layout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <ListView android:id="@+id/messages_list_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</LinearLayout>
+5
source share
4 answers

You can use the search function in eclipse, do a search, "0x7f050007"or go to projectfolder/gen/path/R.javathat contains your resources.

You will find something like this:

public static final int lineItem=0x7f07001c;

Then do a search (in this example) lineItemwith the Eclipses search function. This will lead you to your resource in code.

+2
source

I got this error when using ListView in fragment.

, setAdapter onViewCreated . ( , ListView ).

:

public void onViewCreated(View view,Bundle savedInstanceState){
    ListView list = (ListView) getView().findViewById(R.id.thelist);
    list.setAdapter(mAdapter);
}
+5

For those for whom the other solutions mentioned do not work.

I made this stupid mistake: -

setContentView(R.id.something);

Instead

setContentView(R.layout.something);

This is fixed, and the error disappeared: D

+5
source

Check your import (at the top of your file class). You may have imported

android.R

(which provides access to platform resources) instead

{your_package_name}.R

(you can also leave it blank).

0
source

All Articles