在我的android應用程序中,我使用以下函數從表中檢索列......表中包含值,但它有一個例外。sqlite cursorindexoutofbound exception
public String[] getactivelist(){
Log.v("ppp","getactivelist");
String[] actname=new String[50];
SQLiteDatabase db = this.getWritableDatabase();
Log.v("ppp","dbcrtd");
Cursor cursor = db.rawQuery("SELECT name FROM activelist ORDER BY time ASC", null);
Log.v("ppp","aftrcurser");
int i=0;
Log.v("ppp crsr",cursor.getString(0));
if (cursor.moveToFirst()) {
do {
actname[i]=cursor.getString(0);
Log.v("ppp crsr",cursor.getString(0));
} while (cursor.moveToNext());
}
cursor.close();
db.close();
return actname;
}
日誌貓顯示以下錯誤
04-04 01:19:41.170 2581-2601/com.example.pranavtv.loudspeaker V/ppp﹕ tryandroid.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 2