IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Android Discussion :

Database et Android


Sujet :

Android

  1. #1
    Membre confirmé
    Étudiant
    Inscrit en
    Août 2010
    Messages
    67
    Détails du profil
    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Août 2010
    Messages : 67
    Par défaut Database et Android
    je suis débutant en android et je souhaite votre aide
    je veux exécuter des requête sql mais ca marche pas

    un message qui s'affiche
    the application testé(process test2.test2) has stopped unexpectedly . please try again

    mon code



    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
     
    public void onCreate(Bundle savedInstanceState) {
     
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
     
     
        SQLiteDatabase db;
     
        db = openOrCreateDatabase(
       		"TestingData3.db"
       		, SQLiteDatabase.CREATE_IF_NECESSARY
       		, null
       		);
        db.setVersion(1);
        db.setLocale(Locale.getDefault());
        db.setLockingEnabled(true);
     
        db.execSQL("select locale from android_metadata");
     
        }
    merci

  2. #2
    Membre chevronné Avatar de seeme
    Profil pro
    Inscrit en
    Octobre 2005
    Messages
    430
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France

    Informations forums :
    Inscription : Octobre 2005
    Messages : 430
    Par défaut
    Hum... C'est à quelle ligne qu'il plante? Ta méthode est dans quel type de class?

  3. #3
    Membre confirmé
    Étudiant
    Inscrit en
    Août 2010
    Messages
    67
    Détails du profil
    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Août 2010
    Messages : 67
    Par défaut
    merci seeme de votre intérêt

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
     
    package test2.test2;
     
    import java.util.Locale;
     
    import android.app.Activity;
    import android.database.sqlite.SQLiteDatabase;
    import android.os.Bundle;
     
    public class test2 extends Activity {
        /** Called when the activity is first created. */
     
    //	DatabaseHelper mDbHelper = new DatabaseHelper(this);
     
     
        @Override
        public void onCreate(Bundle savedInstanceState) {
     
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
     
     
        SQLiteDatabase db;
     
        db = openOrCreateDatabase(
       		"TestingData3.db"
       		, SQLiteDatabase.CREATE_IF_NECESSARY
       		, null
       		);
        db.setVersion(1);
        db.setLocale(Locale.getDefault());
        db.setLockingEnabled(true);
     
        db.execSQL("select locale from android_metadata");
     
        }
     
    }
    le problème au niveau de la ligne suivante
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
        db.execSQL("select locale from android_metadata");

  4. #4
    Rédacteur
    Avatar de MrDuChnok
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Juin 2002
    Messages
    2 112
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Juin 2002
    Messages : 2 112
    Par défaut
    Bonjour,

    Afin de t'aider efficacement, il faudrait que tu publie ici le message exact de l'exception.
    Cette exception sera visible dans la console Android (Vue LogCat sur Eclipse).

  5. #5
    Membre confirmé
    Étudiant
    Inscrit en
    Août 2010
    Messages
    67
    Détails du profil
    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Août 2010
    Messages : 67
    Par défaut
    meci MrDuChnok

    dans emulator une message qui s'affiche

    the application testé(process test2.test2) has stopped unexpectedly . please try again
    et dans la console d'Eclipse il n'y a pas d'erreurs
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
     
    2010-08-17 14:44:35 - test2] Android Launch!
    [2010-08-17 14:44:35 - test2] adb is running normally.
    [2010-08-17 14:44:35 - test2] Performing test2.test2.test2 activity launch
    [2010-08-17 14:44:35 - test2] Automatic Target Mode: Preferred AVD 'aqw' is not available. Launching new emulator.
    [2010-08-17 14:44:35 - test2] Launching a new emulator with Virtual Device 'aqw'
    [2010-08-17 14:44:38 - test2] New emulator found: emulator-5556
    [2010-08-17 14:44:38 - test2] Waiting for HOME ('android.process.acore') to be launched...
    [2010-08-17 14:45:21 - test2] HOME is up on device 'emulator-5556'
    [2010-08-17 14:45:21 - test2] Uploading test2.apk onto device 'emulator-5556'
    [2010-08-17 14:45:21 - test2] Installing test2.apk...
    [2010-08-17 14:46:01 - test2] Success!
    [2010-08-17 14:46:02 - test2] Starting activity test2.test2.test2 on device 
    [2010-08-17 14:46:09 - test2] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=test2.test2/.test2 }

  6. #6
    Rédacteur
    Avatar de MrDuChnok
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Juin 2002
    Messages
    2 112
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Juin 2002
    Messages : 2 112
    Par défaut
    Ce n'est pas l'exception.

    Si ton programme déclenche une exception, elle doit s'afficher dans la vue "LogCat"

  7. #7
    Membre confirmé
    Étudiant
    Inscrit en
    Août 2010
    Messages
    67
    Détails du profil
    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Août 2010
    Messages : 67
    Par défaut
    merci Mr DuChnok
    dans logcat

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
     
    08-17 15:14:14.046: DEBUG/AndroidRuntime(361): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
    08-17 15:14:14.046: DEBUG/AndroidRuntime(361): CheckJNI is ON
    08-17 15:14:14.336: DEBUG/AndroidRuntime(361): --- registering native functions ---
    08-17 15:14:15.766: DEBUG/dalvikvm(175): GC_EXPLICIT freed 353 objects / 20640 bytes in 119ms
    08-17 15:14:15.846: DEBUG/PackageParser(59): Scanning package: /data/app/vmdl29110.tmp
    08-17 15:14:16.126: DEBUG/dalvikvm(59): GC_FOR_MALLOC freed 9444 objects / 483960 bytes in 160ms
    08-17 15:14:16.337: INFO/PackageManager(59): Removing non-system package:t2.t2
    08-17 15:14:16.346: INFO/ActivityManager(59): Force stopping package t2.t2 uid=10035
    08-17 15:14:16.366: INFO/Process(59): Sending signal. PID: 327 SIG: 9
    08-17 15:14:16.556: INFO/UsageStats(59): Unexpected resume of com.android.quicksearchbox while already resumed in t2.t2
    08-17 15:14:17.147: WARN/InputManagerService(59): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@43f1fce0
    08-17 15:14:17.666: DEBUG/PackageManager(59): Scanning package t2.t2
    08-17 15:14:17.857: INFO/PackageManager(59): Package t2.t2 codePath changed from /data/app/t2.t2-1.apk to /data/app/t2.t2-2.apk; Retaining data and using new
    08-17 15:14:18.017: INFO/PackageManager(59): /data/app/t2.t2-2.apk changed; unpacking
    08-17 15:14:18.127: DEBUG/installd(34): DexInv: --- BEGIN '/data/app/t2.t2-2.apk' ---
    08-17 15:14:18.497: DEBUG/dalvikvm(368): DexOpt: load 55ms, verify 27ms, opt 3ms
    08-17 15:14:18.517: DEBUG/installd(34): DexInv: --- END '/data/app/t2.t2-2.apk' (success) ---
    08-17 15:14:18.517: WARN/PackageManager(59): Code path for pkg : t2.t2 changing from /data/app/t2.t2-1.apk to /data/app/t2.t2-2.apk
    08-17 15:14:18.517: WARN/PackageManager(59): Resource path for pkg : t2.t2 changing from /data/app/t2.t2-1.apk to /data/app/t2.t2-2.apk
    08-17 15:14:18.528: DEBUG/PackageManager(59):   Activities: t2.t2.t2
    08-17 15:14:18.547: INFO/ActivityManager(59): Force stopping package t2.t2 uid=10035
    08-17 15:14:18.817: INFO/installd(34): move /data/dalvik-cache/data@app@t2.t2-2.apk@classes.dex -> /data/dalvik-cache/data@app@t2.t2-2.apk@classes.dex
    08-17 15:14:18.817: DEBUG/PackageManager(59): New package installed in /data/app/t2.t2-2.apk
    08-17 15:14:19.057: INFO/ActivityManager(59): Force stopping package t2.t2 uid=10035
    08-17 15:14:19.407: DEBUG/dalvikvm(163): GC_EXPLICIT freed 276 objects / 12560 bytes in 296ms
    08-17 15:14:19.429: DEBUG/dalvikvm(125): GC_EXPLICIT freed 343 objects / 14624 bytes in 313ms
    08-17 15:14:19.707: WARN/RecognitionManagerService(59): no available voice recognition services found
    08-17 15:14:20.287: DEBUG/dalvikvm(59): GC_EXPLICIT freed 6587 objects / 429768 bytes in 388ms
    08-17 15:14:20.637: INFO/installd(34): unlink /data/dalvik-cache/data@app@t2.t2-1.apk@classes.dex
    08-17 15:14:20.707: DEBUG/AndroidRuntime(361): Shutting down VM
    08-17 15:14:20.747: DEBUG/dalvikvm(361): Debugger has detached; object registry had 1 entries
    08-17 15:14:20.777: INFO/AndroidRuntime(361): NOTE: attach of thread 'Binder Thread #3' failed
    08-17 15:14:21.817: DEBUG/AndroidRuntime(373): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
    08-17 15:14:21.817: DEBUG/AndroidRuntime(373): CheckJNI is ON
    08-17 15:14:22.206: DEBUG/AndroidRuntime(373): --- registering native functions ---
    08-17 15:14:23.486: INFO/ActivityManager(59): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=t2.t2/.t2 }
    08-17 15:14:23.576: DEBUG/AndroidRuntime(373): Shutting down VM
    08-17 15:14:23.609: DEBUG/dalvikvm(373): Debugger has detached; object registry had 1 entries
    08-17 15:14:23.706: INFO/AndroidRuntime(373): NOTE: attach of thread 'Binder Thread #3' failed
    08-17 15:14:23.836: INFO/ActivityManager(59): Start proc t2.t2 for activity t2.t2/.t2: pid=380 uid=10035 gids={}
    08-17 15:14:24.356: DEBUG/dalvikvm(32): GC_EXPLICIT freed 255 objects / 9712 bytes in 431ms
    08-17 15:14:24.686: DEBUG/dalvikvm(32): GC_EXPLICIT freed 27 objects / 1160 bytes in 248ms
    08-17 15:14:25.116: DEBUG/dalvikvm(32): GC_EXPLICIT freed 2 objects / 64 bytes in 424ms
    08-17 15:14:25.446: DEBUG/AndroidRuntime(380): Shutting down VM
    08-17 15:14:25.446: WARN/dalvikvm(380): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
    08-17 15:14:25.516: ERROR/AndroidRuntime(380): FATAL EXCEPTION: main
    08-17 15:14:25.516: ERROR/AndroidRuntime(380): java.lang.RuntimeException: Unable to start activity ComponentInfo{t2.t2/t2.t2.t2}: android.database.sqlite.SQLiteException: unknown error: Queries cannot be performed using execSQL(), use query() instead.
    08-17 15:14:25.516: ERROR/AndroidRuntime(380):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
    08-17 15:14:25.516: ERROR/AndroidRuntime(380):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
    08-17 15:14:25.516: ERROR/AndroidRuntime(380):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
    08-17 15:14:25.516: ERROR/AndroidRuntime(380):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
    08-17 15:14:25.516: ERROR/AndroidRuntime(380):     at android.os.Handler.dispatchMessage(Handler.java:99)
    08-17 15:14:25.516: ERROR/AndroidRuntime(380):     at android.os.Looper.loop(Looper.java:123)
    08-17 15:14:25.516: ERROR/AndroidRuntime(380):     at android.app.ActivityThread.main(ActivityThread.java:4627)
    08-17 15:14:25.516: ERROR/AndroidRuntime(380):     at java.lang.reflect.Method.invokeNative(Native Method)
    08-17 15:14:25.516: ERROR/AndroidRuntime(380):     at java.lang.reflect.Method.invoke(Method.java:521)
    08-17 15:14:25.516: ERROR/AndroidRuntime(380):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
    08-17 15:14:25.516: ERROR/AndroidRuntime(380):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
    08-17 15:14:25.516: ERROR/AndroidRuntime(380):     at dalvik.system.NativeStart.main(Native Method)
    08-17 15:14:25.516: ERROR/AndroidRuntime(380): Caused by: android.database.sqlite.SQLiteException: unknown error: Queries cannot be performed using execSQL(), use query() instead.
    08-17 15:14:25.516: ERROR/AndroidRuntime(380):     at android.database.sqlite.SQLiteDatabase.native_execSQL(Native Method)
    08-17 15:14:25.516: ERROR/AndroidRuntime(380):     at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1727)
    08-17 15:14:25.516: ERROR/AndroidRuntime(380):     at t2.t2.t2.onCreate(t2.java:27)
    08-17 15:14:25.516: ERROR/AndroidRuntime(380):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
    08-17 15:14:25.516: ERROR/AndroidRuntime(380):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
    08-17 15:14:25.516: ERROR/AndroidRuntime(380):     ... 11 more
    08-17 15:14:25.566: WARN/ActivityManager(59):   Force finishing activity t2.t2/.t2
    08-17 15:14:26.136: WARN/ActivityManager(59): Activity pause timeout for HistoryRecord{43e9da00 t2.t2/.t2}
    08-17 15:14:26.686: WARN/InputManagerService(59): Starting input on non-focused client com.android.internal.view.IInputMethodClient$Stub$Proxy@43ec9858 (uid=10012 pid=246)
    08-17 15:14:32.746: DEBUG/dalvikvm(175): GC_EXPLICIT freed 120 objects / 8960 bytes in 218ms
    08-17 15:14:37.117: INFO/Process(380): Sending signal. PID: 380 SIG: 9
    08-17 15:14:37.377: WARN/InputManagerService(59): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@43edc8c8
    08-17 15:14:37.507: WARN/ActivityManager(59): Activity destroy timeout for HistoryRecord{43e9da00 t2.t2/.t2}
    08-17 15:14:37.683: INFO/ActivityManager(59): Process t2.t2 (pid 380) has died.
    08-17 15:14:38.426: DEBUG/dalvikvm(265): GC_EXPLICIT freed 801 objects / 56656 bytes in 802ms
    08-17 15:15:49.716: DEBUG/SntpClient(59): request time failed: java.net.SocketException: Address family not supported by protocol

  8. #8
    Rédacteur
    Avatar de MrDuChnok
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Juin 2002
    Messages
    2 112
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Juin 2002
    Messages : 2 112
    Par défaut
    Merci.

    Dans ces logs, il y a un message plus parlant :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Caused by: android.database.sqlite.SQLiteException: unknown error: Queries cannot be performed using execSQL(), use query() instead.
    Du coup, as tu essayé de suivre ce conseil ?

  9. #9
    Membre confirmé
    Étudiant
    Inscrit en
    Août 2010
    Messages
    67
    Détails du profil
    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Août 2010
    Messages : 67
    Par défaut
    bonjour

    merci Mr DuChnok pour votre conseil

    cordialement

  10. #10
    Rédacteur
    Avatar de MrDuChnok
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Juin 2002
    Messages
    2 112
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Juin 2002
    Messages : 2 112
    Par défaut
    Si le problème est résolu, je t'invite à cliquer sur le bouton correspondant se trouvant en bas de la page.
    N'hésite pas à poster ton code avec le soucis résolu pour aider d'autres personnes se trouvant dans le même cas que toi.
    Merci.

  11. #11
    Membre confirmé
    Étudiant
    Inscrit en
    Août 2010
    Messages
    67
    Détails du profil
    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Août 2010
    Messages : 67
    Par défaut
    merci MrDuChnok pour votre conseil

    le problème est résolu
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     
       public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
          //  setContentView(R.layout.main);
     
            SQLiteDatabase db;
         	db= SQLiteDatabase.openDatabase(
         	    	"/data/data/t2.t2/databases/TestingData3.db",
         	    	//"sdcard/myfriendsDB",
         	    	null,
         	    	SQLiteDatabase.CREATE_IF_NECESSARY) ;
         	    	Toast.makeText(this, "DB was opened!", 1).show();
         	    	Cursor c1 = db.rawQuery("select locale from android_metadata",null);

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Afficher des données d'un Cursor - Android database
    Par keybon dans le forum Android
    Réponses: 2
    Dernier message: 27/11/2012, 11h52
  2. Android et Database
    Par GGelec dans le forum Android
    Réponses: 3
    Dernier message: 27/07/2012, 10h39
  3. DataBases Android SQLite
    Par salima198710 dans le forum Android
    Réponses: 10
    Dernier message: 02/12/2011, 22h37
  4. Réponses: 4
    Dernier message: 13/01/2011, 14h03

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo