0

この例に基づいてSimple Cursor Adapter problem エラーはxmlレイアウトと関係があると思います

データベースの詳細:

 public static final String question = "quest";
  private static final String DATABASE_NAME = "QuestionDB";
private static final String DATABASE_TABLE = "questions";
   DBAdapter da = new DBAdapter(this);

 // open the database connection
da.open();
// assign to the cursor the ability to loop through the records.
Cursor c = da.getAllContacts();

メソッド getAllContacts(); 以下のこのコードに基づいています

  public Cursor getAllContacts() 
  {
         return db.query(DATABASE_TABLE, new String[] {KEY_ROWID,
   question, possibleAnsOne,possibleAnsTwo,  possibleAnsThree,realQuestion}, null,   null, null, null, null);
}

startManagingCursor(c);

// move to the first element
c.moveToFirst();


 String[] from = new String[]{"quest"};
 int[] to = new int[] { R.id.name_entry };

 SimpleCursorAdapter sca = new SimpleCursorAdapter(this, R.layout.layout_list_example, c, from, to);
 setListAdapter(sca);

これがxmlファイルlayout_list_example.xmlです

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >
    <ListView
        android:id="@android:id/android:list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

</LinearLayout>

list_example_entry.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >
    <TextView
        android:id="@+id/name_entry"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="28dip" />
       <TextView
        android:id="@+id/number_entry"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="28dip" />
</LinearLayout>

コンテンツレビューを設定する拡張コンテンツは、その問題を取り除きました。私は将来のためにそれを覚えています。列が存在しないと表示されたため、列をクエストに戻さなければなりませんでした。アクティビティを実行すると、黒い画面に行が表示され、データのないリストビューだと思います。

エラーログはこちら

05-12 19:52:22.570: E/AndroidRuntime(534): FATAL EXCEPTION: main
05-12 19:52:22.570: E/AndroidRuntime(534): java.lang.RuntimeException: Unable to start activity ComponentInfo{alex.android.basic.databse.questions/alex.android.basic.databse.questions.Result}: java.lang.IllegalArgumentException: column 'question' does not exist
05-12 19:52:22.570: E/AndroidRuntime(534):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
05-12 19:52:22.570: E/AndroidRuntime(534):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
05-12 19:52:22.570: E/AndroidRuntime(534):  at android.app.ActivityThread.access$600(ActivityThread.java:123)
05-12 19:52:22.570: E/AndroidRuntime(534):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
05-12 19:52:22.570: E/AndroidRuntime(534):  at android.os.Handler.dispatchMessage(Handler.java:99)
05-12 19:52:22.570: E/AndroidRuntime(534):  at android.os.Looper.loop(Looper.java:137)
05-12 19:52:22.570: E/AndroidRuntime(534):  at android.app.ActivityThread.main(ActivityThread.java:4424)
05-12 19:52:22.570: E/AndroidRuntime(534):  at java.lang.reflect.Method.invokeNative(Native Method)
05-12 19:52:22.570: E/AndroidRuntime(534):  at java.lang.reflect.Method.invoke(Method.java:511)
05-12 19:52:22.570: E/AndroidRuntime(534):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-12 19:52:22.570: E/AndroidRuntime(534):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-12 19:52:22.570: E/AndroidRuntime(534):  at dalvik.system.NativeStart.main(Native Method)
05-12 19:52:22.570: E/AndroidRuntime(534): Caused by: java.lang.IllegalArgumentException: column 'question' does not exist
05-12 19:52:22.570: E/AndroidRuntime(534):  at android.database.AbstractCursor.getColumnIndexOrThrow(AbstractCursor.java:267)
05-12 19:52:22.570: E/AndroidRuntime(534):  at android.widget.SimpleCursorAdapter.findColumns(SimpleCursorAdapter.java:332)
05-12 19:52:22.570: E/AndroidRuntime(534):  at android.widget.SimpleCursorAdapter.<init>(SimpleCursorAdapter.java:81)
05-12 19:52:22.570: E/AndroidRuntime(534):  at alex.android.basic.databse.questions.Result.onCreate(Result.java:37)
05-12 19:52:22.570: E/AndroidRuntime(534):  at android.app.Activity.performCreate(Activity.java:4465)
05-12 19:52:22.570: E/AndroidRuntime(534):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
05-12 19:52:22.570: E/AndroidRuntime(534):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
4

2 に答える 2

0

これは正しくありません String[] from = new String[]{"quest"};

そのString[]は、カーソルからリストビューにデータをマップするために使用されるため、カーソル内の列の1つの名前である必要があります。

私はあなたがこれを望んでいると思います:

String[] from = new String[]{"question"};

編集

それが見つからない場合は、アクティビティのコンテンツビューを設定する必要があると思います。

setContentView(R.layout.layout_list_example);

編集2

私たちはそれを見ずにそれを見つめていると思います...あなたのクエリでは、KEY_のものを除いて各アイテムを引用符で囲んでください。「質問」など

于 2012-05-12T12:58:03.233 に答える
0

レイアウト xmlを使用している場合はListActivty、id を持つ listview が必要ですandroid:id="@android:id/list"

例:

<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>

したがって、 with を変更するとandroid:id="@android:id/android:list"問題が解決するはずですlayout_list_example.xmlandroid:id="@android:id/list"

お役に立てれば

于 2012-05-12T15:48:00.193 に答える