在這些情況下,有沒有人遇到過這個錯誤?Android SQLite奇怪的錯誤
無法從CursorWindow讀取第1行第8列。
我知道這意味着它試圖讀取列8的數據,但事情是我只有7列,我從來沒有試圖從第8列顯然分配數據。
我的問題是,每當我清除數據並再次開始,它工作正常,然後突然啓動引發錯誤。
這是我的表:
public String CREATE_TABLE = "CREATE TABLE BreakTests (" +
"Id INTEGER PRIMARY KEY AUTOINCREMENT, " +
"Answered_Question_Set_ID INTEGER, " +
"PassValue INTEGER, " +
"Value1 INTEGER, " +
"Value2 INTEGER, " +
"Value3 INTEGER, " +
"Value4 INTEGER, " +
"Value5 INTEGER)";
這些都是我的專欄:
public final String KEY_ID = "Id";
public final String KEY_ANSWERED_QUESTION_SET_ID = "Answered_Question_Set_ID";
public final String KEY_PASS_VALUE = "PassValue";
public final String KEY_VALUE_1 = "Value1";
public final String KEY_VALUE_2 = "Value2";
public final String KEY_VALUE_3 = "Value3";
public final String KEY_VALUE_4 = "Value4";
public final String KEY_VALUE_5 = "Value5";
public final String[] COLUMNS = {KEY_ID, KEY_ANSWERED_QUESTION_SET_ID, KEY_PASS_VALUE, KEY_VALUE_1, KEY_VALUE_2, KEY_VALUE_3, KEY_VALUE_4, KEY_VALUE_5};
這是我的查詢:
public ArrayList<BreakTest> GetForSync() {
ArrayList<BreakTest> tests = new ArrayList<BreakTest>();
String selectQuery = "SELECT Id, Answered_Question_Set_ID, PassValue, Value1, Value2, Value3, Value4, Value5 FROM BreakTests";
Cursor cursor = Shared.db.getReadableDatabase().rawQuery(selectQuery, new String[] { });
BreakTest breakTest;
if (cursor.moveToFirst()) {
do {
breakTest = new BreakTest();
breakTest.Id = cursor.getInt(cursor.getInt(cursor.getColumnIndex(KEY_ID)));
breakTest.Answered_Question_Set_ID = cursor.getInt(cursor.getColumnIndex(KEY_ANSWERED_QUESTION_SET_ID));
breakTest.PassValue = cursor.getInt(cursor.getColumnIndex(KEY_PASS_VALUE));
breakTest.Value1 = cursor.getInt(cursor.getColumnIndex(KEY_VALUE_1));
breakTest.Value2 = cursor.getInt(cursor.getColumnIndex(KEY_VALUE_2));
breakTest.Value3 = cursor.getInt(cursor.getColumnIndex(KEY_VALUE_3));
breakTest.Value4 = cursor.getInt(cursor.getColumnIndex(KEY_VALUE_4));
breakTest.Value5 = cursor.getInt(cursor.getColumnIndex(KEY_VALUE_5));
tests.add(breakTest);
} while (cursor.moveToNext());
}
return tests;
}
我已經與Android Studio和SQLite的工作了一段時間了,我從來沒有遇到過這個問題。
任何意見/反饋將非常感激!
我們能有堆棧跟蹤的副本? –
您現有的表只能有7列,您可以添加新的coumnrecently,試圖改變表或清除應用數據,然後再次嘗試 – MathaN
喬希:每當我試圖獲取完整的堆棧跟蹤我的應用程序崩潰,我只能給予是例外信息。 MathaN:我之前已經清除了數據,並且它可以正常工作一段時間,然後突然開始發生錯誤。 – James