Simple Cursor Adapter problem 私はエラーがXMLレイアウトエラーこの例に基づいて
データベースの詳細で何かのTODOだと思う:
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ファイルは、コンテンツのレビューを設定
<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>
<?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>
list_example_entry.xml
拡張内容は、その問題を取り除くlayout_list_example.xml。私はそれを覚えています。私は列が存在しないと言っているので、私は列をクエストに戻さなければなりませんでした。ここで
は、エラーログがこれはそれがからデータをマップするために使用される文字列は、[]、カーソル内の列の1つの名前である必要があり、誤ったString[] from = new String[]{"quest"};
ある
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)
どのような質問/ prオームレム? – Barak
コンテンツビューのヘルプを設定しましたか? – Barak
カーソル内にデータがある場合、または空白行がない場合は、適切に呼び出していない(または空の文字列です)。あなたの 'from'配列**の内容は、あなたがカーソルを引っ張った列の名前でなければならないことを知っています... – Barak