Question

Don't know if I am just too tired to reason anymore, but I ma having an annoying problem with a ListActivity not finding its ListView resource. Annoying, since I have implemented this in the same way in two other activities in the same app.

Very basic...

Layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/backrepeat"
    android:tileMode="repeat"
    android:orientation="vertical">
    <ListView android:id="@android:id/list"
              android:layout_width="match_parent"
              android:layout_height="match_parent"/>
</LinearLayout>

Activity:

setListAdapter(new ArrayAdapter<String>(this, android.R.id.list, fileList ));   

I have searched around here, and found other posts with obvious mistakes... anyone any ideas?

Getting the Resource Not Found exception

09-10 14:25:40.366: E/AndroidRuntime(2392):     android.content.res.Resources$NotFoundException: File  from xml type layout resource ID #0x102000a

Thanks!

Was it helpful?

Solution

Change to

setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, fileList )); 

Look at the constructors of ArrayAdapter. Use the one that suits you

http://developer.android.com/reference/android/widget/ArrayAdapter.html

Example:

String[] GENRES = new String[] {
        "Action", "Adventure", "Animation", "Children", "Comedy",
    "Documentary", "Drama",
        "Foreign", "History", "Independent", "Romance", "Sci-Fi",
    "Television", "Thriller"
    };
setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, GENRES));

GENRES is string array. android.R.layout.simple_list_item_1 is the layout for your list. this refers to the activity context.

Android looks for a resource with id mentioned. If it does not find you get ResourceNotFoundException

OTHER TIPS

you should change this:

setListAdapter(new ArrayAdapter<String>(YourActivity.this, android.R.layout.simple_list_item_1,android.R.id.list, fileList ));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top