Wir haben die xyz.sqlite-Datei erstellt (in der wir eine Tabelle mit dem Namen BOOK haben) und sie im Ordner „raw“ gespeichert, dann die Datei kopiert und die Datenbank zur Laufzeit erstellt, was in allen Android-Versionen bis Android 8 einwandfrei funktioniert. Wenn ich sie jedoch auf Android 9 (Pie) auf dem Emulator ausführe, erhalte ich die unten genannte Fehlermeldung ...
Ich habe nach der Lösung gesucht, aber nichts hat funktioniert ... Jede Hilfe wäre hilfreich Vielen Dank...
09-13 00:55:49.536 5685-5685/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.kosmos.zentrale, PID: 5685
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.kosmos.zentrale/com.kosmos.zentrale.CatalogNew}: android.database.sqlite.SQLiteException: no such table: BOOK (code 1 SQLITE_ERROR): , while compiling: SELECT * FROM BOOK ORDER BY _erscheinungsjahr DESC , _uniqueID ASC
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: android.database.sqlite.SQLiteException: no such table: BOOK (code 1 SQLITE_ERROR): , while compiling: SELECT * FROM BOOK ORDER BY _erscheinungsjahr DESC , _uniqueID ASC
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:903)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:514)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteQuery.(SQLiteQuery.java:37)
at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:46)
at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1408)
at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1255)
at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1126)
at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1294)
at com.mobisys.android.database.BookDatabase.query(BookDatabase.java:68)
at com.mobisys.android.database.HelperDatabase.getBooks(HelperDatabase.java:57)
at com.kosmos.zentrale.CatalogNew.setCursorAdapter(CatalogNew.java:617)
at com.kosmos.zentrale.CatalogNew.onCreate(CatalogNew.java:120)
at android.app.Activity.performCreate(Activity.java:7136)
at android.app.Activity.performCreate(Activity.java:7127)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Unten finden Sie unseren Datenbank-Erstellungscode
public class BookDatabase {
public static final String DATABASE_NAME = "xyz.sqlite";
public static final int DATABASE_VERSION = 2;
private static String DB_PATH = "/data/data/"+"/databases/";
private OpenHelper gameHelper;
private SQLiteDatabase database;
public BookDatabase(Context context){
try {
DB_PATH = "/data/data/"+context.getPackageName()+"/databases/";
gameHelper=new OpenHelper(context);
gameHelper.createDataBase();
openDataBase();
} catch (IOException e) {
gameHelper=null;
e.printStackTrace();
}
catch (SQLException e) {
gameHelper=null;
e.printStackTrace();
}
}
public void openDataBase() throws SQLException{
//Open the database
String myPath = DB_PATH + DATABASE_NAME;
database = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READWRITE);
}
public long insert(String table, ContentValues values){
return database.insert(table, null, values);
}
public long delete(String table, String where, String[] whereArgs){
return database.delete(table, where, whereArgs);
}
public int update(String table, ContentValues values, String whereClause, String[] whereArgs){
return database.update(table, values, whereClause, whereArgs);
}
public long countRows(String query){
return DatabaseUtils.longForQuery(database, query, null);
}
public Cursor query(String table,String[] columns, String selection,String[] selectionArgs,String groupBy,String having,String orderBy){
return database.query(table, columns, selection, selectionArgs, groupBy, having, orderBy);
}
public void close(){
database.close();
gameHelper.close();
}
public Cursor rawQuery(String sql,String[] args){
return database.rawQuery(sql, args);
}
private class OpenHelper extends SQLiteOpenHelper {
Context context;
OpenHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
this.context=context;
}
/**
* Creates a empty database on the system and rewrites it with your own database.
* */
public void createDataBase() throws IOException{
boolean dbExist = checkDataBase();
if(dbExist){
//do nothing - database already exist
}else{
//By calling this method and empty database will be created into the default system path
//of your application so we are gonna be able to overwrite that database with our database.
this.getReadableDatabase();
try {
copyDataBase();
} catch (IOException e) {
throw new Error("Error copying database");
}
}
}
/**
* Check if the database already exist to avoid re-copying the file each time you open the application.
* @return true if it exists, false if it doesn't
*/
private boolean checkDataBase(){
try{
File databasePath = context.getDatabasePath(DATABASE_NAME);
return databasePath.exists();
}catch(Exception e){
return false;
}
}
/**
* Copies your database from your local assets-folder to the just created empty database in the
* system folder, from where it can be accessed and handled.
* This is done by transfering bytestream.
* */
private void copyDataBase() throws IOException{
//Open your local db as the input stream
InputStream myInput = context.getResources().openRawResource(R.raw.xyz);
// Path to the just created empty db
String outFileName = DB_PATH + DATABASE_NAME;
//Open the empty db as the output stream
OutputStream myOutput = new FileOutputStream(outFileName);
//transfer bytes from the inputfile to the outputfile
byte[] buffer = new byte[1024];
int length;
while ((length = myInput.read(buffer))>0){
myOutput.write(buffer, 0, length);
}
//Close the streams
myOutput.flush();
myOutput.close();
myInput.close();
}
@Override
public void onCreate(SQLiteDatabase arg0) {
}
@Override
public void onUpgrade(SQLiteDatabase arg0, int oldVersion, int newVersion) {
}
}
Wir haben die xyz.sqlite-Datei erstellt (in der wir eine Tabelle mit dem Namen BOOK haben) und sie im Ordner „raw“ gespeichert, dann die Datei kopiert und die Datenbank zur Laufzeit erstellt, was in allen Android-Versionen bis Android 8 einwandfrei funktioniert. Wenn ich sie jedoch auf Android 9 (Pie) auf dem Emulator ausführe, erhalte ich die unten genannte Fehlermeldung ...
Ich habe nach der Lösung gesucht, aber nichts hat funktioniert ... Jede Hilfe wäre hilfreich Vielen Dank...
Vielen Dank.
[code]09-13 00:55:49.536 5685-5685/? E/AndroidRuntime: FATAL EXCEPTION: main Process: com.kosmos.zentrale, PID: 5685 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.kosmos.zentrale/com.kosmos.zentrale.CatalogNew}: android.database.sqlite.SQLiteException: no such table: BOOK (code 1 SQLITE_ERROR): , while compiling: SELECT * FROM BOOK ORDER BY _erscheinungsjahr DESC , _uniqueID ASC at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:6669) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) Caused by: android.database.sqlite.SQLiteException: no such table: BOOK (code 1 SQLITE_ERROR): , while compiling: SELECT * FROM BOOK ORDER BY _erscheinungsjahr DESC , _uniqueID ASC at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method) at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:903) at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:514) at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588) at android.database.sqlite.SQLiteProgram.(SQLiteProgram.java:58) at android.database.sqlite.SQLiteQuery.(SQLiteQuery.java:37) at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:46) at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1408) at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1255) at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1126) at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1294) at com.mobisys.android.database.BookDatabase.query(BookDatabase.java:68) at com.mobisys.android.database.HelperDatabase.getBooks(HelperDatabase.java:57) at com.kosmos.zentrale.CatalogNew.setCursorAdapter(CatalogNew.java:617) at com.kosmos.zentrale.CatalogNew.onCreate(CatalogNew.java:120) at android.app.Activity.performCreate(Activity.java:7136) at android.app.Activity.performCreate(Activity.java:7127) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:6669) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) [/code]
Unten finden Sie unseren Datenbank-Erstellungscode
[code]public class BookDatabase { public static final String DATABASE_NAME = "xyz.sqlite"; public static final int DATABASE_VERSION = 2; private static String DB_PATH = "/data/data/"+"/databases/"; private OpenHelper gameHelper; private SQLiteDatabase database;
/** * Creates a empty database on the system and rewrites it with your own database. * */ public void createDataBase() throws IOException{
boolean dbExist = checkDataBase();
if(dbExist){
//do nothing - database already exist }else{
//By calling this method and empty database will be created into the default system path //of your application so we are gonna be able to overwrite that database with our database.
this.getReadableDatabase();
try {
copyDataBase();
} catch (IOException e) {
throw new Error("Error copying database");
}
}
}
/** * Check if the database already exist to avoid re-copying the file each time you open the application. * @return true if it exists, false if it doesn't */ private boolean checkDataBase(){
/** * Copies your database from your local assets-folder to the just created empty database in the * system folder, from where it can be accessed and handled. * This is done by transfering bytestream. * */ private void copyDataBase() throws IOException{
//Open your local db as the input stream InputStream myInput = context.getResources().openRawResource(R.raw.xyz);
// Path to the just created empty db String outFileName = DB_PATH + DATABASE_NAME;
//Open the empty db as the output stream OutputStream myOutput = new FileOutputStream(outFileName);
//transfer bytes from the inputfile to the outputfile byte[] buffer = new byte[1024]; int length; while ((length = myInput.read(buffer))>0){ myOutput.write(buffer, 0, length); }
//Close the streams myOutput.flush(); myOutput.close(); myInput.close();
}
@Override public void onCreate(SQLiteDatabase arg0) { }
@Override public void onUpgrade(SQLiteDatabase arg0, int oldVersion, int newVersion) { }
Ich arbeite mit SQLCipher, um meine Datenbank in meiner Android-App zu verschlüsseln, stehe aber vor einem Problem, bei dem ich die Datenbank nicht mit der richtigen Passphrase öffnen kann. Wenn ich...
Ich entwickle eine Java -Desktop -Anwendung, die SQLite als Datenbank verwendet. Alles funktioniert während der Entwicklung gut. Wenn ich jedoch ein Setup (Installationsprogramm) für meine Anwendung...
Ich verwende die AFNetworking -Version „2.5.4“ und erstelle eine multipartform-data -Anfrage.
In meinem Fall funktioniert der Code unter iOS8 einwandfrei, aber unter iOS 7 gibt es ein Problem. Es...
Vor dem Problem habe ich bereits mit einer Windows-Anwendung getestet/debuggt und wie COM3 oder COM5 geöffnet/gelesen und es hat perfekt funktioniert, aber als ANDROID-Plattform, die auf einem...