我在服务器json url中有值,然后获取这些值,然后存储到本地数据库中。但是当我得到这些值并存储到本地数据库中时,我无法打开数据库。
SQLiteDatabase checkDB = null;
try {
checkDB = SQLiteDatabase.openDatabase("/data/data/com.example.testjson/databases/Details", null,
SQLiteDatabase.OPEN_READONLY);
checkDB.close();
db.updateDetails(store);
} catch (SQLiteException e) {
// database doesn't exist yet.
// Log.i("DatabaseInserted", "No Found");
db.insertDetails(store);
}
日志:
12-15 17:23:17.555: E/SQLiteLog(17270): (14) cannot open file at line 32516 of [00bb9c9ce4]
12-15 17:23:17.555: E/SQLiteLog(17270): (14) os_unix.c:32516: (2) open(/data/data/com.example.beacon/databases/BeaconDetails) -
12-15 17:23:17.560: E/SQLiteDatabase(17270): Failed to open database '/data/data/com.example.beacon/databases/BeaconDetails'.
12-15 17:23:17.560: E/SQLiteDatabase(17270): android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database
12-15 17:23:17.560: E/SQLiteDatabase(17270): at android.database.sqlite.SQLiteConnection.nativeOpen(Native Method)
12-15 17:23:17.560: E/SQLiteDatabase(17270): at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:339)
12-15 17:23:17.560: E/SQLiteDatabase(17270): at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:236)
12-15 17:23:17.560: E/SQLiteDatabase(17270): at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:515)
12-15 17:23:17.560: E/SQLiteDatabase(17270): at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:207)
12-15 17:23:17.560: E/SQLiteDatabase(17270): at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:178)
12-15 17:23:17.560: E/SQLiteDatabase(17270): at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:891)
12-15 17:23:17.560: E/SQLiteDatabase(17270): at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:859)
12-15 17:23:17.560: E/SQLiteDatabase(17270): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:696)
12-15 17:23:17.560: E/SQLiteDatabase(17270): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:671)
12-15 17:23:17.560: E/SQLiteDatabase(17270): at com.example.beacon.MainActivity$JsonTask.doInBackground(MainActivity.java:226)
12-15 17:23:17.560: E/SQLiteDatabase(17270): at com.example.beacon.MainActivity$JsonTask.doInBackground(MainActivity.java:1)
12-15 17:23:17.560: E/SQLiteDatabase(17270): at android.os.AsyncTask$2.call(AsyncTask.java:287)
12-15 17:23:17.560: E/SQLiteDatabase(17270): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
12-15 17:23:17.560: E/SQLiteDatabase(17270): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
12-15 17:23:17.560: E/SQLiteDatabase(17270): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
12-15 17:23:17.560: E/SQLiteDatabase(17270): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
12-15 17:23:17.560: E/SQLiteDatabase(17270): at java.lang.Thread.run(Thread.java:841)
答案 0 :(得分:1)
您在更新或插入之前关闭了Db!
将陈述交换为:
db.updateDetails(store);
checkDB.close();