6

If I get the error "android.content.res.Resources$NotFoundException: Resource ID #0x7f050007 type #0x12 is not valid" can I find some what this resource is 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> 
4
  • You mean that you do not use R.id? Could you hint me why? Commented Oct 11, 2011 at 7:55
  • without knowing what you have you tried to implement, how can we suggest? Commented Oct 11, 2011 at 7:58
  • You surely set proper layout for your activity? Commented Oct 11, 2011 at 8:19
  • Just a hint: Use @id/android:list for your ListView. Look here --> developer.android.com/reference/android/app/ListActivity.html Commented Oct 11, 2011 at 8:46

4 Answers 4

5

I Got this error when using ListView in a Fragment.

Resolved by moving the setAdapter lines to the onViewCreated function of the Fragment. (makes sense that before the view is created the ListView is invalid).

so you get :

public void onViewCreated(View view,Bundle savedInstanceState){ ListView list = (ListView) getView().findViewById(R.id.thelist); list.setAdapter(mAdapter); } 
Sign up to request clarification or add additional context in comments.

Comments

5

For those whom other mentioned solutions don't work.

I did this silly mistake:-

setContentView(R.id.something); 

Instead of

setContentView(R.layout.something); 

Corrected that, and error was gone :D

Comments

3

You can either use the search function in eclipse, search for "0x7f050007" or go to projectfolder/gen/path/R.java that contains your resources.

You'll find something like this:

public static final int lineItem=0x7f07001c; 

Then search for(in this example) lineItem with Eclipses search function. It'll take you to your resource in code.

Comments

0

Check your imports (at the top of your class-file). Maybe you imported

android.R 

(which provides access to the platform-resources) instead of

{your_package_name}.R 

(you can also leave it blank).

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.