A small app is written, and data needs to be stored in sqlite. Follow the instructions in this document to create a database file as follows:
db_aimu = SQLiteDatabase.openOrCreateDatabase("test.db", null);
Logcat error during running:
02-22 09:16:28.214: E/SQLiteLog(26781): (14) cannot open file at line 30176 of [00bb9c9ce4]02-22 09:16:28.222: E/SQLiteLog(26781): (14) os_unix.c:30176: (2) open(//test.db) - 02-22 09:16:28.331: E/SQLiteDatabase(26781): Failed to open database 'test.db'.02-22 09:16:28.331: E/SQLiteDatabase(26781): android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database02-22 09:16:28.331: E/SQLiteDatabase(26781): at android.database.sqlite.SQLiteConnection.nativeOpen(Native Method)02-22 09:16:28.331: E/SQLiteDatabase(26781): at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:209)02-22 09:16:28.331: E/SQLiteDatabase(26781): at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:193)02-22 09:16:28.331: E/SQLiteDatabase(26781): at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)02-22 09:16:28.331: E/SQLiteDatabase(26781): at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185)02-22 09:16:28.331: E/SQLiteDatabase(26781): at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177)02-22 09:16:28.331: E/SQLiteDatabase(26781): at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:804)02-22 09:16:28.331: E/SQLiteDatabase(26781): at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:789)02-22 09:16:28.331: E/SQLiteDatabase(26781): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:694)02-22 09:16:28.331: E/SQLiteDatabase(26781): at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:709)02-22 09:16:28.331: E/SQLiteDatabase(26781): at com.test.test.<init>(test.java:21)02-22 09:16:28.331: E/SQLiteDatabase(26781): at com.test.test.getInstance(test.java:34)02-22 09:16:28.331: E/SQLiteDatabase(26781): at com.test.MainActivity$2.run(MainActivity.java:71)
It seems that opening the data file failed.
No reason was found when I checked the official documents online. Finally, someone mentioned:
I faced this problem, it was because in 4.2, there is multi users support, and if you are testing with non-admin user, you cannot acess/data path ..
In my case I'm using the path:
Context. getFilesDir (). getAbsolutePath (). replace ("files", "databases") + File. separator
Http://androiddev.orkitra.com /? P = 13793
That is to say, the multi-user mechanism is introduced in androi4.2. Normal users cannot access the/data directory under the root directory, and thus cannot create database files. My android simulator is indeed the latest version 4.2, so this problem occurs.
The problem is solved by knowing the cause. Use context. getFilesDir (). getAbsolutePath () in the above method to obtain the absolute path.