2012-05-12 8 views
0

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) 
+0

どのような質問/ prオームレム? – Barak

+0

コンテンツビューのヘルプを設定しましたか? – Barak

+0

カーソル内にデータがある場合、または空白行がない場合は、適切に呼び出していない(または空の文字列です)。あなたの 'from'配列**の内容は、あなたがカーソルを引っ張った列の名前でなければならないことを知っています... – Barak

答えて

0

ですカーソルをリストビューに移動します。

私はあなたがこの欲しいと思う:それは、私はあなたが活動モミコンテンツビューを設定する必要があることを推測することを見つけることができない場合

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

EDIT

を。

setContentView(R.layout.layout_list_example); 

EDIT私たちはそれを見ずに、それを見つめてきた...あなたのクエリに考える2

は、KEY_ 1を除き、引用符で各項目を囲みます。などの「質問」、

+0

悲しいことに、私の問題を解決できませんでした。エラーは "あなたのコンテンツはリストビューのwhos id属性がandroid.R.id.listである必要があります"というエラーが引用符で囲まれています – al23dev

+0

私の答えが – Barak

+0

に更新されました。正確なエラーは何でしたか? – Barak

0

あなたがListActivtyを使用している場合は、あなたのレイアウトXMLは元のID android:id="@android:id/list"

とリストビューを持っている必要があります。

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

だから、android:id="@android:id/list"であなたのlayout_list_example.xmlandroid:id="@android:id/android:list"を変更すると、あなたを修正する必要があります問題

希望すると便利です

+0

変更を加えましたが、まだエラーが表示されています何が間違っている可能性がありますか? – al23dev

+0

同じエラーが発生していますか?あなたの質問を編集し、あなたのログの猫 –

+0

私のポストの最初の部分は、列の問題についての話を投稿する必要があります。エラーをトリガする出力を追加しました – al23dev

関連する問題