Android Sqlite错误android.database.sqlite.SQLiteCantOpenDatabaseException:无法打开数据库文件

时间:2012-11-20 09:46:15

标签: android sqlite

我使用Galaxy tab 2(4.0.3)测试应用时遇到此错误 但是当我使用Galaxy SI(2.3.6)和Akai(4.0.3)进行测试时,它可以正常工作。

我们使用已创建的数据库,当应用程序启动时,我会将它从助手复制到数据库目录(如果不存在)

 11-20 11:20:05.170: I/SqliteDatabaseCpp(12921): sqlite returned: error code = 11, msg = database corruption at line 48112 of [ed759d5a9e], db=/data/data/com.xprts.mobilesales/databases/testDB
11-20 11:20:05.170: I/SqliteDatabaseCpp(12921): sqlite returned: error code = 11, msg = database disk image is malformed, db=/data/data/com.xprts.mobilesales/databases/testDB
11-20 11:20:05.170: E/SqliteDatabaseCpp(12921): sqlite3_exec - Failed to set synchronous mode = 1(Normal) 
11-20 11:20:05.170: E/DefaultDatabaseErrorHandler(12921): Corruption reported by sqlite on database: /data/data/com.xprts.mobilesales/databases/MobileSales.DB
11-20 11:20:05.170: E/DefaultDatabaseErrorHandler(12921): deleting the database file: /data/data/com.xprts.mobilesales/databases/MobileSales.DB
11-20 11:20:05.170: I/SqliteDatabaseCpp(12921): sqlite returned: error code = 14, msg = cannot open file at line 27803 of [ed759d5a9e], db=/data/data/com.xprts.mobilesales/databases/testDB
11-20 11:20:05.170: I/SqliteDatabaseCpp(12921): sqlite returned: error code = 14, msg = os_unix.c: open() at line 27803 - "" errno=2 path=/data/data/com.xprts.mobilesales/databases/MobileSales.DB, db=/data/data/com.xprts.mobilesales/databases/testDB
11-20 11:20:05.170: E/SqliteDatabaseCpp(12921): sqlite3_open_v2("/data/data/com.xprts.mobilesales/databases/MobileSales.DB", &handle, 2, NULL) failed
11-20 11:20:05.170: I/SqliteDatabaseCpp(12921): sqlite returned: error code = 14, msg = cannot open file at line 27803 of [ed759d5a9e], db=/data/data/com.xprts.mobilesales/databases/testDB
11-20 11:20:05.170: I/SqliteDatabaseCpp(12921): sqlite returned: error code = 14, msg = os_unix.c: open() at line 27803 - "" errno=2 path=/data/data/com.xprts.mobilesales/databases/MobileSales.DB, db=/data/data/com.xprts.mobilesales/databases/testDB
11-20 11:20:05.170: E/SqliteDatabaseCpp(12921): sqlite3_open_v2("/data/data/com.xprts.mobilesales/databases/MobileSales.DB", &handle, 1, NULL) failed
11-20 11:20:05.178: E/SQLiteDatabase(12921): Failed to open the database. closing it.
11-20 11:20:05.178: E/SQLiteDatabase(12921): android.database.sqlite.SQLiteCantOpenDatabaseException: unable to open database file
11-20 11:20:05.178: E/SQLiteDatabase(12921):    at android.database.sqlite.SQLiteDatabase.dbopen(Native Method)
11-20 11:20:05.178: E/SQLiteDatabase(12921):    at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:1124)
11-20 11:20:05.178: E/SQLiteDatabase(12921):    at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:1075)
11-20 11:20:05.178: E/SQLiteDatabase(12921):    at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:1135)
11-20 11:20:05.178: E/SQLiteDatabase(12921):    at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:1075)
11-20 11:20:05.178: E/SQLiteDatabase(12921):    at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:1051)
11-20 11:20:05.178: E/SQLiteDatabase(12921):    at com.xprts.mobilesales.database.DBAdapter.checkDataBase(DBAdapter.java:118)
11-20 11:20:05.178: E/SQLiteDatabase(12921):    at com.xprts.mobilesales.database.DBAdapter.createDataBase(DBAdapter.java:89)
11-20 11:20:05.178: E/SQLiteDatabase(12921):    at com.xprts.mobilesales.database.DBAdapter.access$0(DBAdapter.java:87)
11-20 11:20:05.178: E/SQLiteDatabase(12921):    at com.xprts.mobilesales.database.DBAdapter$1.run(DBAdapter.java:32)
11-20 11:20:05.178: E/SQLiteDatabase(12921):    at java.lang.Thread.run(Thread.java:856)

解决方案


最后它的确有效 我的数据库已损坏(仅在Galaxy Tab 2中) 我已经尝试SQLJet数据库浏览器来检查我的数据库 这个sql语句中的错误是(DEFAULT'''10''') 现在它工作得很好,谢谢

CREATE TABLE [MB_DEVICE_SEQUENCES] (
[COMP_ID] TEXT(10)  NOT NULL,
[DEVICE_CODE] TEXT(10)  NOT NULL,
[SEQ_TYPE] TEXT(4000) DEFAULT '''10''' NOT NULL,
[COMP_YEAR] NUMERIC(4)  NOT NULL,
[SEQ_CODE] TEXT(10)  NOT NULL,
[DEVICE_SEQ_FROM_NUMBER] NUMERIC(20)  NOT NULL,
[DEVICE_SEQ_TO_NUMBER] NUMERIC(20)  NOT NULL,
[DEVICE_SEQ_INTERVAL] TEXT(20)  NULL,
[DEVICE_SEQ_CONSUMED_COUNT] NUMERIC(20)  NULL,
PRIMARY KEY ([COMP_ID],[DEVICE_CODE],[SEQ_TYPE],[COMP_YEAR],[SEQ_CODE],[DEVICE_SEQ_FROM_NUMBER])
)

1 个答案:

答案 0 :(得分:0)

确保文件副本成功完成,复制后数据库已损坏。

也可能是您在预先存在的数据库上没有必要的元数据。 您是否按照here ?

中的步骤操作了