我正在尝试在其他设备上运行我的应用程序,但它在打开时崩溃但是它完全适用于其他设备我不知道为什么它会给我这个错误
Caused by: java.lang.IllegalStateException: Couldn't read row 0, col 8 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
at android.database.CursorWindow.nativeGetLong(Native Method)
at android.database.CursorWindow.getLong(CursorWindow.java:524)
at android.database.CursorWindow.getInt(CursorWindow.java:591)
at android.database.AbstractWindowedCursor.getInt(AbstractWindowedCursor.java:69)
at abtech.waiteriano.com.waitrer.UseYourIp.onCreate(UseYourIp.java:74)
作为此行中的错误
if (data.getInt(8)== 1) {
multipleLogIn.setChecked(true);
}else {
multipleLogIn.setChecked(false);
}if (data.getInt(9)== 1) {
x = 1;
passCode.setChecked(true);
}else
passCode.setChecked(false);
这是我的Curser In数据库助手
package abtech.waiteriano.com.waitrer.data_base_helper;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
/**
* Created by Mitch on 2016-05-13.
*/
public class DatabaseHelper extends SQLiteOpenHelper {
public static final String DATABASE_NAME = "OutLet_DB_SETUP.db";
public static final String TABLE_NAME = "SETUP_OutIP";
public static final String ID = "ID";
public static final String IP = "IP";
public static final String UName = "UName";
public static final String PW = "PW";
public static final String DBName = "DBName";
public static final String OutletName = "OutletName";
public static final String WS = "WS";
public static final String Rest = "Rest";
public static final String MultipleLogin = "MultipleLogin";
public static final String repeatPassCode = "repeatPassCode";
public static final String USER_ID = "UserID";
public static final String USER_PW = "UserPW";
public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, 1);
}
@Override
public void onCreate(SQLiteDatabase db) {
String createTable = "CREATE TABLE " + TABLE_NAME + " (ID INTEGER PRIMARY KEY , " +
" OutletName TEXT,IP TEXT,UName TEXT,PW TEXT,DBName TEXT,WS INTEGER,Rest INTEGER,MultipleLogin INTEGER,repeatPassCode INTEGER)";
db.execSQL(createTable);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP IF TABLE EXISTS " + TABLE_NAME);
onCreate(db);
}
public boolean addData(int _ID, String _IP, String _UName, String _PW, String _DBName, String _OutletName, String _WS, String _Rest, Boolean _MultipleLogin, Boolean _repeatPassCode ) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(ID, _ID);
contentValues.put(OutletName, _OutletName);
contentValues.put(IP, _IP);
contentValues.put(UName, _UName);
contentValues.put(PW, _PW);
contentValues.put(DBName, _DBName);
contentValues.put(WS, _WS);
contentValues.put(Rest, _Rest);
contentValues.put(MultipleLogin, _MultipleLogin);
contentValues.put(repeatPassCode, _repeatPassCode);
long result = db.insert(TABLE_NAME, null, contentValues);
//if date as inserted incorrectly it will return -1
if (result == -1) {
db.execSQL("Update " + TABLE_NAME + " Set IP = '" + _IP + "' ,UName = '" + _UName + "', PW = '" + _PW + "',DBName = '" + _DBName + "',WS = '" + _WS + "',Rest = '" + _Rest + "',MultipleLogin = " + _MultipleLogin.compareTo(false) + ",repeatPassCode = " + _repeatPassCode.compareTo(false) + " Where ID = " + _ID);
return true;
} else {
return true;
}
}
public Cursor getListContents(String _ID) {
SQLiteDatabase db = this.getWritableDatabase();
// onCreate(db);
Cursor data = db.rawQuery("SELECT * FROM " + TABLE_NAME + _ID, null);
return data;
}
public int DeleteContents(String _ID) {
SQLiteDatabase db = this.getWritableDatabase();
int r = db.delete(TABLE_NAME, " ID = " + _ID, null);
return r;
}
}
答案 0 :(得分:0)
尝试更改以下内容:
public Cursor getListContents(String _ID) {
SQLiteDatabase db = this.getWritableDatabase();
Cursor data = db.rawQuery("SELECT * FROM " + TABLE_NAME + _ID, null);
return data;
}
为:
public Cursor getListContents(String _ID) { // Parameter unused, could remove.
SQLiteDatabase db = this.getWritableDatabase();
Cursor data = db.rawQuery("SELECT * FROM " + TABLE_NAME, null); // REMOVED _ID
return data;
}
您似乎无意中在选择查询中创建了错误的表名。