因此,我的应用程序的用户崩溃报告中有此错误。这是报告:
android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
at android.database.AbstractCursor.checkPosition(AbstractCursor.)
at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.)
at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:50)
at rs.androidaplikacije.zastaveigradovi.Kviz10Hard.nextQuestionGrad(Kviz10Hard.)
at rs.androidaplikacije.zastaveigradovi.Kviz10Hard.access$1(Kviz10Hard.)
at rs.androidaplikacije.zastaveigradovi.Kviz10Hard$2.run(Kviz10Hard.java:68)
at android.os.Handler.handleCallback(Handler.)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.)
at android.app.ActivityThread.main(ActivityThread.)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.)
at dalvik.system.NativeStart.main(Native Method)
这是上面提到的代码:
private void nextQuestionGrad() {
flag.setVisibility(View.GONE);
dodatnoPitanje.setVisibility(View.VISIBLE);
TestAdapter mDbHelper = new TestAdapter(this);
DataBaseHelper myDbHelper = new DataBaseHelper(this);
if(!myDbHelper.checkDataBase()){
mDbHelper.createDatabase();
}
try{
mDbHelper.open();
Cursor c = mDbHelper.getTestDataGradovi(mCurrentID);
List<Answer> labels = new ArrayList<Answer>();
labels.add(new Answer(c.getString(2), true));
labels.add(new Answer(c.getString(3), false));
labels.add(new Answer(c.getString(4), false));
labels.add(new Answer(c.getString(5), false));
tacanOdg = c.getString(2);
Collections.shuffle(labels);
dodatnoPitanje.setText(c.getString(1));
bOdgovor1.setText(labels.get(0).option);
bOdgovor1.setTag(labels.get(0));
bOdgovor1.setOnClickListener(clickListenerGrad);
bOdgovor2.setText(labels.get(1).option);
bOdgovor2.setTag(labels.get(1));
bOdgovor2.setOnClickListener(clickListenerGrad);
bOdgovor3.setText(labels.get(2).option);
bOdgovor3.setTag(labels.get(2));
bOdgovor3.setOnClickListener(clickListenerGrad);
bOdgovor4.setText(labels.get(3).option);
bOdgovor4.setTag(labels.get(3));
bOdgovor4.setOnClickListener(clickListenerGrad);
score.setText("Score: " + brojacTacnihOdgovora);
}finally{
mDbHelper.close();
}
}
我用于此类的适配器类的一部分:
public Cursor getTestDataGradovi(long id){
try{
String sql ="SELECT * FROM tblGradovi WHERE _ID = " + id;
Cursor c = mDb.rawQuery(sql, null);
if (c!=null){
c.moveToNext();
}
return c;
}catch (SQLException mSQLException){
Log.e(TAG, "getTestData >>"+ mSQLException.toString());
throw mSQLException;
}
}
谁能告诉我问题出在哪里?错误行 (Kviz10Hard.) 在这里:
labels.add(new Answer(c.getString(2), true));