アプリケーションに次のエラー メッセージが表示されます。
05-13 09:05:53.218: E/AndroidRuntime(5339): FATAL EXCEPTION: main
05-13 09:05:53.218: E/AndroidRuntime(5339): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.unserekinder/com.example.unserekinder.Ereignisse}: java.lang.IllegalStateException: Couldn't read row 1, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
05-13 09:05:53.218: E/AndroidRuntime(5339): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
05-13 09:05:53.218: E/AndroidRuntime(5339): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
05-13 09:05:53.218: E/AndroidRuntime(5339): at android.app.ActivityThread.access$600(ActivityThread.java:141)
05-13 09:05:53.218: E/AndroidRuntime(5339): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
05-13 09:05:53.218: E/AndroidRuntime(5339): at android.os.Handler.dispatchMessage(Handler.java:99)
05-13 09:05:53.218: E/AndroidRuntime(5339): at android.os.Looper.loop(Looper.java:137)
05-13 09:05:53.218: E/AndroidRuntime(5339): at android.app.ActivityThread.main(ActivityThread.java:5041)
05-13 09:05:53.218: E/AndroidRuntime(5339): at java.lang.reflect.Method.invokeNative(Native Method)
05-13 09:05:53.218: E/AndroidRuntime(5339): at java.lang.reflect.Method.invoke(Method.java:511)
05-13 09:05:53.218: E/AndroidRuntime(5339): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-13 09:05:53.218: E/AndroidRuntime(5339): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-13 09:05:53.218: E/AndroidRuntime(5339): at dalvik.system.NativeStart.main(Native Method)
05-13 09:05:53.218: E/AndroidRuntime(5339): Caused by: java.lang.IllegalStateException: Couldn't read row 1, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
05-13 09:05:53.218: E/AndroidRuntime(5339): at android.database.CursorWindow.nativeGetString(Native Method)
05-13 09:05:53.218: E/AndroidRuntime(5339): at android.database.CursorWindow.getString(CursorWindow.java:434)
05-13 09:05:53.218: E/AndroidRuntime(5339): at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:51)
05-13 09:05:53.218: E/AndroidRuntime(5339): at com.example.unserekinder.Ereignisse.datenfuerlistviewereignis(Ereignisse.java:49)
05-13 09:05:53.218: E/AndroidRuntime(5339): at com.example.unserekinder.Ereignisse.onCreate(Ereignisse.java:28)
05-13 09:05:53.218: E/AndroidRuntime(5339): at android.app.Activity.performCreate(Activity.java:5104)
05-13 09:05:53.218: E/AndroidRuntime(5339): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
05-13 09:05:53.218: E/AndroidRuntime(5339): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
05-13 09:05:53.218: E/AndroidRuntime(5339): ... 11 more
私のテーブルは次のようになります。
public static final String ereignisid = "id";
public static final String TABLE_NAME_EREIGNIS="ereignis";
public static final String EREIGNISNAME = "ereignisname";
public static final String EREIGNISZEIT = "ereigniszeit";
public static final String EREIGNISGENAUERES = "ereignisgenaueres";
public static final String KINDID = "kindid";
private static final String TABLE_EREIGNIS_CREATE = "CREATE TABLE IF NOT EXISTS " + TABLE_NAME_EREIGNIS + " (" + ereignisid + " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ EREIGNISNAME + " TEXT, " + EREIGNISZEIT + " TEXT, " + EREIGNISGENAUERES + " TEXT, " + KINDID + " INTEGER, FOREIGN KEY (" + KINDID + ") REFERENCES " + TABLE_NAME_Kind + "(" + id + "));";
これは、エラーが発生する関数です。
private ArrayList<Ereignis> datenfuerlistviewereignis(){
DBHelper db = new DBHelper(this);
ArrayList<Ereignis> arr = new ArrayList<Ereignis>();
ListView lv = (ListView) findViewById(R.id.lvEreignisse);
id = getIntent().getIntExtra("kinderid", 0);
System.out.println("SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSss" + id);
Cursor c = db.selectEreignis(id);
c.moveToFirst();
int count = c.getCount();
int i = 0;
while(c.moveToNext())
{
// here happens the error!
arr.add(new Ereignis(c.getString(c.getColumnIndex("ereigniszeit")), c.getString(c.getColumnIndex("ereignisname")) ));
i++;
}
if(arr.size() > 0){
return arr;
}
else{
ArrayList<Ereignis> arrempty = new ArrayList<Ereignis>();
arrempty.add(new Ereignis("Keine Daten vorhanden", " "));
return arrempty;
}
}
誰かが私の間違いを教えてもらえますか??
編集:
これはselectEreignis()
public Cursor selectEreignis(int kindid){
SQLiteDatabase db = getReadableDatabase();
Cursor cursor = db.rawQuery("SELECT ereignisname FROM EREIGNIS WHERE KINDID = " + kindid, null);
System.out.println("HALLLIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII" + cursor.getCount());
return cursor;
}