Aller au contenu
View in the app

A better way to browse. Learn more.

Forum de Frandroid

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[Résolu] Creer une base de données sur la SD Card

Featured Replies

Posté(e)

Bonjour

J'essaye de créer une base de données sur la SD Card mais je n'y arrive pas. Voilà mon code :

    public class DatabaseHelper extends SQLiteOpenHelper {

       Context    context;

       public DatabaseHelper(Context context) {
           super(context, "/sdcard/my_folder/my_base", null, 1);
           this.context = context;
       }

       @Override
       public void onCreate(SQLiteDatabase db) {
       }

       @Override
       public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
       }
   }

Le LocCat me retourne cela :

08-26 16:44:37.477: ERROR/AndroidRuntime(23576): Uncaught handler: thread main exiting due to uncaught exception

08-26 16:44:37.477: ERROR/AndroidRuntime(23576): java.lang.RuntimeException: Unable to start activity ComponentInfo{ts.S9000.planning_exterieur/ts.S9000.planning_exterieur.Libelles}: java.lang.IllegalArgumentException: File /sdcard/technic-soft/planning_exterieur/libelles contains a path separator

08-26 16:44:37.477: ERROR/AndroidRuntime(23576): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)

08-26 16:44:37.477: ERROR/AndroidRuntime(23576): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)

08-26 16:44:37.477: ERROR/AndroidRuntime(23576): at android.app.ActivityThread.access$2200(ActivityThread.java:119)

08-26 16:44:37.477: ERROR/AndroidRuntime(23576): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)

08-26 16:44:37.477: ERROR/AndroidRuntime(23576): at android.os.Handler.dispatchMessage(Handler.java:99)

08-26 16:44:37.477: ERROR/AndroidRuntime(23576): at android.os.Looper.loop(Looper.java:123)

08-26 16:44:37.477: ERROR/AndroidRuntime(23576): at android.app.ActivityThread.main(ActivityThread.java:4363)

08-26 16:44:37.477: ERROR/AndroidRuntime(23576): at java.lang.reflect.Method.invokeNative(Native Method)

08-26 16:44:37.477: ERROR/AndroidRuntime(23576): at java.lang.reflect.Method.invoke(Method.java:521)

08-26 16:44:37.477: ERROR/AndroidRuntime(23576): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)

08-26 16:44:37.477: ERROR/AndroidRuntime(23576): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)

08-26 16:44:37.477: ERROR/AndroidRuntime(23576): at dalvik.system.NativeStart.main(Native Method)

08-26 16:44:37.477: ERROR/AndroidRuntime(23576): Caused by: java.lang.IllegalArgumentException: File /sdcard/technic-soft/planning_exterieur/libelles contains a path separator

08-26 16:44:37.477: ERROR/AndroidRuntime(23576): at android.app.ApplicationContext.makeFilename(ApplicationContext.java:1444)

08-26 16:44:37.477: ERROR/AndroidRuntime(23576): at android.app.ApplicationContext.openOrCreateDatabase(ApplicationContext.java:472)

08-26 16:44:37.477: ERROR/AndroidRuntime(23576): at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:193)

08-26 16:44:37.477: ERROR/AndroidRuntime(23576): at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:98)

08-26 16:44:37.477: ERROR/AndroidRuntime(23576): at ts.S9000.DB.DBAdapter.open(DBAdapter.java:39)

08-26 16:44:37.477: ERROR/AndroidRuntime(23576): at ts.S9000.planning_exterieur.Libelles.onCreate(Libelles.java:52)

08-26 16:44:37.477: ERROR/AndroidRuntime(23576): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)

08-26 16:44:37.477: ERROR/AndroidRuntime(23576): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)

08-26 16:44:37.477: ERROR/AndroidRuntime(23576): ... 11 more

A priori il ne faut pas de "/" dans le nom de la base... Comment faire alors pour créer cette base sur la SD Card ?

Merci d'avance

Modifié par TsCyrille

Posté(e)
  • Auteur

J'ai réussi à trouver.... Voici comment j'ai défini ma classe DatabaseHelper :

    public class DatabaseHelper extends SQLiteOpenHelper {

       String NAME_DB;
       String PATH_DB;
       Context    context;

       public DatabaseHelper(Context context, String _pathDB, String _nameDB) {
           super(context, _nameDB, null, 1);

           this.context = context;
           NAME_DB = _nameDB;
           PATH_DB = _pathDB;
       }

       @Override
       public void onCreate(SQLiteDatabase db) {
       }

       @Override
       public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
       }

       public SQLiteDatabase openDataBase() throws SQLException{
           boolean continu = true;
           SQLiteDatabase dbRetour = null;

           try {
               if (!checkDataBase()) {
                   SQLiteDatabase dbCreate = SQLiteDatabase.openOrCreateDatabase(PATH_DB + NAME_DB, null);

                   if (dbCreate != null) {
                       dbCreate.execSQL("create table my_table (_id integer primary key autoincrement, col1 text not null);");            
                       dbCreate.close();
                   } else
                       continu = false;
               }

               if (continu)
                   dbRetour = SQLiteDatabase.openDatabase(PATH_DB + NAME_DB, null, SQLiteDatabase.OPEN_READWRITE);
           } catch (Exception e) {

           }

           return dbRetour;
       }

       private boolean checkDataBase() {
           SQLiteDatabase checkDB = null;

           try{
               checkDB = SQLiteDatabase.openDatabase(PATH_DB + NAME_DB, null, SQLiteDatabase.OPEN_READONLY);
           }catch (SQLiteException e) {
               //database does't exist yet.
           }

           if (checkDB != null)
               checkDB.close();

           return checkDB != null ? true : false;
       }

   }

Archivé

Ce sujet est désormais archivé et ne peut plus recevoir de nouvelles réponses.

Account

Navigation

Rechercher

Rechercher

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.