在Android中使用sqlite数据库时,出现了一个奇怪的问题。
我在一张表中插入约500个Enteries,但是当该表有大约260-270个Enteres时,它显示此异常:
sqLiteCantOpenDatabaseException
码:
public last_open open() throws SQLException {db = DBHelper.getWritableDatabase();return this;}
public void close() {DBHelper.close();}
public static void insert(
String STUDENT_ID,
String COURSE_ID,
String PACKAGE_ID,
String ITEM_NAME,
String ITEM_ID,
String LAST_OPEN
){
try{
ContentValues initialValues = new ContentValues();
initialValues.put(T_STUDENT_ID,STUDENT_ID);
initialValues.put(T_COURSE_ID, COURSE_ID);
initialValues.put(T_PACKAGE_ID, PACKAGE_ID);
initialValues.put(T_ITEM_NAME,ITEM_NAME);
initialValues.put(T_ITEM_ID, ITEM_ID);
initialValues.put(T_LAST_OPEN,LAST_OPEN);
// db.insert("LAST_OPEN", null, initialValues);
db.execSQL("DELETE FROM LAST_OPEN WHERE STUDENT_ID="+STUDENT_ID+" AND COURSE_ID="+COURSE_ID+" AND PACKAGE_ID="+PACKAGE_ID+" AND ITEM_ID="+ITEM_ID+" AND ITEM_NAME='"+ITEM_NAME+"';");
db.execSQL("INSERT INTO LAST_OPEN(STUDENT_ID,COURSE_ID,PACKAGE_ID,ITEM_NAME,ITEM_ID,LAST_OPEN) VALUES ("+STUDENT_ID+","+COURSE_ID+","+PACKAGE_ID+","+"'"+ITEM_NAME+"'"+","+ITEM_ID+","+"'"+LAST_OPEN+"'"+");");
}catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
这些是我正在使用的方法::
日志:
SqliteDatabaseCpp(586): sqlite returned: error code = 14, msg = cannot open file at line 27360 of [8609a15dfa], db=/data/data/com.cuelearn.main/databases/cuelearn
SqliteDatabaseCpp(586): sqlite returned: error code = 14, msg = os_unix.c: open() at line 27360 - "" errno=24 path=/data/data/com.cuelearn.main/databases, db=/data/data/com.cuelearn.main/databases/cuelearn
SqliteDatabaseCpp(586): sqlite returned: error code = 14, msg = statement aborts at 28: [DELETE FROM LAST_OPEN WHERE STUDENT_ID=95 AND COURSE_ID=2 AND PACKAGE_ID=13 AND ITEM_ID=267 AND ITEM_NAME='Chapter';] , db=/data/data/com.cuelearn.main/databases/cuelearn
enter code here
System.err(586): android.database.sqlite.SQLiteCantOpenDatabaseException: error code 14: unable to open database file
我不知道如何解决这个问题,我也没有找到原因。我已经看到有人在尝试从资产中复制数据库时遇到此异常。但是,就我而言,我没有复制数据库。请帮助我使用Android 4.0.3吗?
最佳答案
您可能试图打开一个已经打开的数据库文件。