-1

このアクティビティを開始しようとすると、このエラーが発生します。

01-31 02:19:19.558: E/AndroidRuntime(1318): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.prva/com.example.prva.ListView}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'

ListActivity:

package com.example.prva;

import android.app.ListActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v4.widget.SimpleCursorAdapter;


public class ListView extends ListActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.listview);
        fillData();
        }

    private void fillData() {
        // Get all of the notes from the database and create the item list
        Cursor c = DatabaseManager.getAllData();
        startManagingCursor(c);

        String[] from = new String[] { DatabaseManager.TABLE_COLUMN_ONE };
        int[] to = new int[] { R.id.text1 };

        // Now create an array adapter and set it to display using our row
        SimpleCursorAdapter notes =
            new SimpleCursorAdapter(this, R.layout.notes_row, c, from, to);
        setListAdapter(notes);
    }
    }

私のlistviewxml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ListView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="326dp" >
    </ListView>

</LinearLayout>

どのIDがリストであるリストビューを持っているので、これを理解していませんか?

4

2 に答える 2

1

android.R.id.list名前の下にあるデフォルトを使用する必要があります@android:idname で独自のID を@+id作成します。list

したがって、代わりに:

android:id="@+id/list"

以下を使用します。

android:id="@android:id/list"
于 2013-01-31T02:25:16.973 に答える
1

ListView id を@android:id/listこれに変更すると、問題が解決します @android:id/list。List Activity には、..これが役立つことを願っています

于 2013-01-31T02:26:32.047 に答える