mercredi 25 février 2015

Can't create SQLite database

So, I've tried to create a SQLite DB in Android, after it runs the code it CREATES the database, but the app crashes.


I have 2 classes (MainActivity and banco) where banco is the database class(NOT DB HELPER)


banco.class



public void criaDB() {
public File sdcard = Environment.getExternalStorageDirectory();
public String pasta = sdcard.getAbsolutePath() + File.separator + "appMaps" + File.separator;

String path = pasta + NOME_DATABASE;
SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(path, null); //line 53
}


MainActivity.class



static banco db_class = new banco();
db = db_class.criaDB(); //line 133


LogCat



02-25 16:41:06.445: E/AndroidRuntime(785): FATAL EXCEPTION: main
02-25 16:41:06.445: E/AndroidRuntime(785): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.googlemapsapi/com.example.googlemapsapi.MainActivity}: android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database
02-25 16:41:06.445: E/AndroidRuntime(785): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
02-25 16:41:06.445: E/AndroidRuntime(785): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
02-25 16:41:06.445: E/AndroidRuntime(785): at android.app.ActivityThread.access$600(ActivityThread.java:130)
02-25 16:41:06.445: E/AndroidRuntime(785): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
02-25 16:41:06.445: E/AndroidRuntime(785): at android.os.Handler.dispatchMessage(Handler.java:99)
02-25 16:41:06.445: E/AndroidRuntime(785): at android.os.Looper.loop(Looper.java:137)
02-25 16:41:06.445: E/AndroidRuntime(785): at android.app.ActivityThread.main(ActivityThread.java:4745)
02-25 16:41:06.445: E/AndroidRuntime(785): at java.lang.reflect.Method.invokeNative(Native Method)
02-25 16:41:06.445: E/AndroidRuntime(785): at java.lang.reflect.Method.invoke(Method.java:511)
02-25 16:41:06.445: E/AndroidRuntime(785): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
02-25 16:41:06.445: E/AndroidRuntime(785): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
02-25 16:41:06.445: E/AndroidRuntime(785): at dalvik.system.NativeStart.main(Native Method)
02-25 16:41:06.445: E/AndroidRuntime(785): Caused by: android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database
02-25 16:41:06.445: E/AndroidRuntime(785): at android.database.sqlite.SQLiteConnection.nativeOpen(Native Method)
02-25 16:41:06.445: E/AndroidRuntime(785): at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:209)
02-25 16:41:06.445: E/AndroidRuntime(785): at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:193)
02-25 16:41:06.445: E/AndroidRuntime(785): at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
02-25 16:41:06.445: E/AndroidRuntime(785): at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185)
02-25 16:41:06.445: E/AndroidRuntime(785): at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177)
02-25 16:41:06.445: E/AndroidRuntime(785): at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:804)
02-25 16:41:06.445: E/AndroidRuntime(785): at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:789)
02-25 16:41:06.445: E/AndroidRuntime(785): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:694)
02-25 16:41:06.445: E/AndroidRuntime(785): at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:709)
02-25 16:41:06.445: E/AndroidRuntime(785): at com.example.googlemapsapi.banco.abreDB(banco.java:53)
02-25 16:41:06.445: E/AndroidRuntime(785): at com.example.googlemapsapi.MainActivity.onCreate(MainActivity.java:133)
02-25 16:41:06.445: E/AndroidRuntime(785): at android.app.Activity.performCreate(Activity.java:5008)
02-25 16:41:06.445: E/AndroidRuntime(785): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
02-25 16:41:06.445: E/AndroidRuntime(785): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)


obs: it creates the database, but the app crashes.


Aucun commentaire:

Enregistrer un commentaire