Vista de lista de Android: excepción de recurso no encontrado

I've got problem with Listview in Android. Then I try to set adapter to a listview I got Resource Not Found Exception.

Mi código:

public class MyActivity extends Activity {
    ArrayList<String> list;

    public void onCreate(Bundle savedInstanceState) {
        list = new ArrayList<String>();

        listView = (ListView)findViewById(;
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,, list);

And in my main.xml I've got:

<ListView android:id="@+id/CheckpointList" android:layout_height="wrap_content" android:layout_width="fill_parent"></ListView>

I've tried to clean and refesh project - no effects...

¿Cómo resolver este problema?


preguntado el 08 de noviembre de 11 a las 12:11

2 Respuestas

The resource you hand over to the ArrayAdapter should not be the id of the ListView. It should be the textViewResourceId - which is basically which TextView-layout-id you want your items, in the list, to be rendered as.

One of the standards is e.g. android.R.layout.simple_list_item_1.

Here's an example of a simple ListView:

public class ListviewExample extends Activity
    private ListView listView;
    private String listView_data[] = {"Android","iPhone","BlackBerry","AndroidPeople"};

    public void onCreate(Bundle icicle)
        listView = (ListView) findViewById(;
        // By using setAdapter method in listview we add the string array to the ListView.
        listView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1 , listView_data));

Respondido el 02 de junio de 12 a las 19:06

The ressource you hand over to the ArrayAdapter should not be the id of the listview. It should be the layout ressource of the textview in the listview. Look at the documentation: ArrayAdapter(Context context, int textViewResourceId, List objects)

respondido 08 nov., 11:16

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.