Ik geloof dat de database in feite met succes is gekopieerd en geladen (geopend) en dat het probleem is dat de gekopieerde database geen tabel heeft met de naam Dictionary1 wanneer u het volgende probeert:-
Cursor cursor = sd.query("Dictionary1" ,null, null, null, null, null, null);
Volgens at com.elytelabs.myapplication.MainActivity.fetchData(MainActivity.java:142)
U moet dus de tabelnaam corrigeren zodat deze overeenkomt met de tabel in de gekopieerde database .
Misschien wilt u deze Q&A gebruiken om database-informatie weer te geven.
De berichten:-
11-22 23:14:56.455 13193-13193/com.elytelabs.myapplication E/SQLiteLog: (14) cannot open file at line 30052 of [b3bb660af9]
11-22 23:14:56.455 13193-13193/com.elytelabs.myapplication E/SQLiteLog: (14) os_unix.c:30052: (2) open(/data/data/com.elytelabs.myapplication/databases/dictionary.db) -
11-22 23:14:56.455 13193-13193/com.elytelabs.myapplication E/SQLiteDatabase: Failed to open database '/data/data/com.elytelabs.myapplication/databases/dictionary.db'.
android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database
etc .........
resultaat van wanneer de checkDatabase
methode wordt aangeroepen omdat de database op dat moment niet is gevonden omdat deze niet is gekopieerd van de activa (zoals het zou moeten doen).
De methode gebruikt de getReadableDatabase
methode om te proberen te zien of de database bestaat. Deze methode drukt altijd de stacktrace af.
Een alternatieve benadering zou kunnen zijn om:-
private boolean checkDataBase(){
// this.getReadableDatabase();
SQLiteDatabase checkDB = null;
try{
String myPath = DB_PATH ;
checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);
}catch(SQLiteException e){
//database does't exist yet.
}
if(checkDB != null){
checkDB.close();
}
return checkDB != null ? true : false;
}
met:-
private boolean checkDataBase(){
File db = new File(DB_PATH);
if(db.exists()) return true;
File dir = new File(db.getParent());
if (!dir.exists()) {
dir.mkdirs();
}
return false;
}
Dit probeert te zien of het databasebestand bestaat (en creëert ook niet-bestaande directory's in het pad, bijvoorbeeld in sommige gevallen bestaat de databasedirectory niet.)
Als het bovenstaande wordt gebruikt, zijn uw berichten meer als:-
11-22 23:14:56.525 13193-13193/com.elytelabs.myapplication E/SQLiteLog: (1) no such table: Dictionary1
11-22 23:14:56.525 13193-13193/com.elytelabs.myapplication D/AndroidRuntime: Shutting down VM
11-22 23:14:56.525 13193-13193/com.elytelabs.myapplication E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.elytelabs.myapplication, PID: 13193
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.elytelabs.myapplication/com.elytelabs.myapplication.MainActivity}: android.database.sqlite.SQLiteException: no such table: Dictionary1 (code 1): , while compiling: SELECT * FROM Dictionary1
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2342)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2404)
at android.app.ActivityThread.access$900(ActivityThread.java:154)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1315)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5296)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:707)
Caused by: android.database.sqlite.SQLiteException: no such table: Dictionary1 (code 1): , while compiling: SELECT * FROM Dictionary1
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1316)
at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1163)
at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1034)
at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1202)
at com.elytelabs.myapplication.MainActivity.fetchData(MainActivity.java:142)
at com.elytelabs.myapplication.MainActivity.onCreate(MainActivity.java:82)