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

Composants graphiques Android Discussion :

Exception sur le click d'un bouton


Sujet :

Composants graphiques Android

  1. #1
    Nouveau Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2012
    Messages
    11
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2012
    Messages : 11
    Points : 1
    Points
    1
    Par défaut Exception sur le click d'un bouton
    Bonjour à tous.

    Je suis en train de découvrir le développement Android depuis maintenant 3 mois. Au niveau des IHM, pas de soucis, j'arrive a faire ce dont j'ai besoin.

    Par contre je bloque un peu sur la BDD SQLITE intégré.

    Donc je veux faire un truc tout simple. J'ai mon IHM avec un bouton. Quand je clique sur ce bouton j'ecris dans ma base de donnée.

    Par la suite il faut que je verifie si l'ajout c'est bien effectuer avec des requete SQL dans l'ADB Shell.

    Mais quand je clique sur mon bouton mon app plante dans la MV.

    Voila le code et le logcat.

    Activty Principale:

    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
    package my.TUBDD.Visites;
     
    import android.app.Activity;
    import android.os.Bundle;
     
    public class TUBDDVisitesActivity extends Activity 
    {
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) 
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
     
     
        }
     
        public void save()
        {
        	Clients cl = new Clients(1,"TEST");
    		cl.sauver();
        }
     
     
    }
    Classe Clients
    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
    package my.TUBDD.Visites;
     
    import java.sql.Date;
    import java.sql.Time;
    import java.util.Calendar;
     
    import my.TUBDD.Visites.R;
    import my.TUBDD.Visites.SqiliteLocal;
    import android.app.Application;
    import android.content.ContentValues;
    import android.database.Cursor;
    import android.database.SQLException;
    import android.database.sqlite.SQLiteDatabase;
    import android.database.sqlite.SQLiteOpenHelper;
    import android.view.View;
    import android.widget.TextView;
    import android.widget.Toast;
     
    public class Clients extends Application
     
    	{
     
    	 	private int ID;
    	    private String nom;
     
    	    public Clients(int ID, String Nom ) 
    	    {
    	        this.ID = ID;
    	        this.nom = Nom;
    	    }
     
    	    /**
                     * base de données
                     */
    		  private SQLiteOpenHelper m_dbHelper;
     
     
    	public void sauver() 
    		{
    		// TODO Auto-generated method stub
    		String mess="Reussi";       
            m_dbHelper = new SqiliteLocal(getApplicationContext());
            SQLiteDatabase db = m_dbHelper.getWritableDatabase();
    		ContentValues values = new ContentValues();
    		values.put("ID", ID);
    		values.put("NOM", nom);
    		try
    		{
    		db.insertOrThrow("CLIENTS", null, values); //insertion d'un enregistrement
    		}
    		catch (SQLException e)
    			{
    				mess ="Erreur insertion";
    			}
    		 Toast.makeText(getApplicationContext(),mess,	Toast.LENGTH_SHORT).show();
    		}
     
     
    }
    Et ma BDD
    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
    package my.TUBDD.Visites;
     
    import android.content.Context;
    import android.database.sqlite.SQLiteDatabase;
    import android.database.sqlite.SQLiteOpenHelper;
     
     
    public class SqiliteLocal extends SQLiteOpenHelper {
     
    	private static final String DATABASE_NAME = "client.db";
        private static final int DATABASE_VERSION = 1;
     
        private static final String CREATE_SQL = "CREATE TABLE CLIENT ("
                        + "ID INTEGER PRIMARY KEY AUTOINCREMENT,"
                        + "NOM TEXT"
                        + ");";
     
        private static final String DROP_SQL = "DROP TABLE IF EXISTS CLIENTS;";
     
    	public SqiliteLocal(Context context) {
    		super(context, DATABASE_NAME, null, DATABASE_VERSION);
    		// TODO Auto-generated constructor stub
    	}
     
    	@Override
    	public void onCreate(SQLiteDatabase db) 
    	{
    		//db.openOrCreateDatabase
    		db.execSQL(CREATE_SQL);
    	}
     
    	@Override
    	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    		db.execSQL(DROP_SQL);
    		onCreate(db);
     
    	}
     
    }
    Voila le logcat:

    06-19 14:34:50.205: D/AndroidRuntime(578): Shutting down VM
    06-19 14:34:50.215: W/dalvikvm(578): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
    06-19 14:34:50.295: E/AndroidRuntime(578): FATAL EXCEPTION: main
    06-19 14:34:50.295: E/AndroidRuntime(578): java.lang.IllegalStateException: Could not find a method save(View) in the activity class my.TUBDD.Visites.TUBDDVisitesActivity for onClick handler on view class android.widget.Button with id 'button1'
    06-19 14:34:50.295: E/AndroidRuntime(578): at android.view.View$1.onClick(View.java:3031)
    06-19 14:34:50.295: E/AndroidRuntime(578): at android.view.View.performClick(View.java:3511)
    06-19 14:34:50.295: E/AndroidRuntime(578): at android.view.View$PerformClick.run(View.java:14105)
    06-19 14:34:50.295: E/AndroidRuntime(578): at android.os.Handler.handleCallback(Handler.java:605)
    06-19 14:34:50.295: E/AndroidRuntime(578): at android.os.Handler.dispatchMessage(Handler.java:92)
    06-19 14:34:50.295: E/AndroidRuntime(578): at android.os.Looper.loop(Looper.java:137)
    06-19 14:34:50.295: E/AndroidRuntime(578): at android.app.ActivityThread.main(ActivityThread.java:4424)
    06-19 14:34:50.295: E/AndroidRuntime(578): at java.lang.reflect.Method.invokeNative(Native Method)
    06-19 14:34:50.295: E/AndroidRuntime(578): at java.lang.reflect.Method.invoke(Method.java:511)
    06-19 14:34:50.295: E/AndroidRuntime(578): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
    06-19 14:34:50.295: E/AndroidRuntime(578): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
    06-19 14:34:50.295: E/AndroidRuntime(578): at dalvik.system.NativeStart.main(Native Method)
    06-19 14:34:50.295: E/AndroidRuntime(578): Caused by: java.lang.NoSuchMethodException: save [class android.view.View]
    06-19 14:34:50.295: E/AndroidRuntime(578): at java.lang.Class.getConstructorOrMethod(Class.java:460)
    06-19 14:34:50.295: E/AndroidRuntime(578): at java.lang.Class.getMethod(Class.java:915)
    06-19 14:34:50.295: E/AndroidRuntime(578): at android.view.View$1.onClick(View.java:3024)
    06-19 14:34:50.295: E/AndroidRuntime(578): ... 11 more
    Merci d'avance a tous ce qui m'aideront.

    PS: Je ne suis vraiment pas douée en programmation, mais j'aimerais que au moins ça marche
    Je sais que je suis pas loin mais je ne vois pas ce qu'il manque :/

  2. #2
    Membre régulier
    Homme Profil pro
    Inscrit en
    Avril 2008
    Messages
    176
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Avril 2008
    Messages : 176
    Points : 106
    Points
    106
    Par défaut
    hello
    tu peux ajouter le code de la gestion du clique du "button1" et aussi comme l'id est en autoincrement pas la peine d'ajouter la valeur dans la table
    @+

  3. #3
    Expert éminent

    Homme Profil pro
    Ingénieur systèmes et réseaux
    Inscrit en
    Février 2007
    Messages
    4 253
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur systèmes et réseaux
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Février 2007
    Messages : 4 253
    Points : 7 618
    Points
    7 618
    Billets dans le blog
    3
    Par défaut
    Allez... un petit effort:
    java.lang.IllegalStateException: Could not find a method save(View) in the activity class ....


    Il y a bien une méthode save dans ta classe, mais elle n'a pas la même signature (pas de paramètre 'view').
    N'oubliez pas de cliquer sur mais aussi sur si un commentaire vous a été utile !
    Et surtout

  4. #4
    Membre régulier
    Homme Profil pro
    Inscrit en
    Avril 2008
    Messages
    176
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Avril 2008
    Messages : 176
    Points : 106
    Points
    106
    Par défaut
    c'est pour cela que j'ai demandé à voir la gestion du clique

  5. #5
    Expert éminent

    Homme Profil pro
    Ingénieur systèmes et réseaux
    Inscrit en
    Février 2007
    Messages
    4 253
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur systèmes et réseaux
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Février 2007
    Messages : 4 253
    Points : 7 618
    Points
    7 618
    Billets dans le blog
    3
    Par défaut
    Citation Envoyé par megaloplex Voir le message
    c'est pour cela que j'ai demandé à voir la gestion du clique
    Oui mais il y avait déjà tout:
    "android:onClick dans le XML"

    Et la fonction "save" dans l'activity
    N'oubliez pas de cliquer sur mais aussi sur si un commentaire vous a été utile !
    Et surtout

  6. #6
    Nouveau Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2012
    Messages
    11
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2012
    Messages : 11
    Points : 1
    Points
    1
    Par défaut
    Merci pour vos réponses. C'est trés gentil.

    Alors pour l'auto incrément de l'ID je crois que j'ai compris, c'est à dire que je peux supprimer cette ligne ?

    Et pour le code de la gestion de l’événement de mon bouton je ne comprends pas trop ?

    J'ai un onClick qui s'appelle save sur ce button1 si c'est ça que vous voulez savoir.

    Mais voila mon code XML de ma view.

    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
    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/RelativeLayout1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
     
        <TextView
            android:id="@+id/TextView1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:text="Test Unitaire Classe Clients" />
     
        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/TextView1"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="53dp"
            android:text="Sauver Clients" android:onClick="save"/>
     
    </RelativeLayout>

    EDIT: Je crois que j'ai compris, je test et je vous tiens au jus dans la foulé.

  7. #7
    Nouveau Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2012
    Messages
    11
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2012
    Messages : 11
    Points : 1
    Points
    1
    Par défaut
    Bon be j'ai essayé de rajouter les parametre View comme ceci a ma methode save():

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    public void save(View view)
        {
        	Clients cl = new Clients(1,"Urban");
    		cl.sauver();
        }
    Mais l'app plante quand meme apres l'appuie du bouton.

    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
    06-19 16:00:18.022: D/gralloc_goldfish(629): Emulator without GPU emulation detected.
    06-19 16:00:25.202: D/AndroidRuntime(629): Shutting down VM
    06-19 16:00:25.202: W/dalvikvm(629): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
    06-19 16:00:25.279: E/AndroidRuntime(629): FATAL EXCEPTION: main
    06-19 16:00:25.279: E/AndroidRuntime(629): java.lang.IllegalStateException: Could not execute method of the activity
    06-19 16:00:25.279: E/AndroidRuntime(629): 	at android.view.View$1.onClick(View.java:3044)
    06-19 16:00:25.279: E/AndroidRuntime(629): 	at android.view.View.performClick(View.java:3511)
    06-19 16:00:25.279: E/AndroidRuntime(629): 	at android.view.View$PerformClick.run(View.java:14105)
    06-19 16:00:25.279: E/AndroidRuntime(629): 	at android.os.Handler.handleCallback(Handler.java:605)
    06-19 16:00:25.279: E/AndroidRuntime(629): 	at android.os.Handler.dispatchMessage(Handler.java:92)
    06-19 16:00:25.279: E/AndroidRuntime(629): 	at android.os.Looper.loop(Looper.java:137)
    06-19 16:00:25.279: E/AndroidRuntime(629): 	at android.app.ActivityThread.main(ActivityThread.java:4424)
    06-19 16:00:25.279: E/AndroidRuntime(629): 	at java.lang.reflect.Method.invokeNative(Native Method)
    06-19 16:00:25.279: E/AndroidRuntime(629): 	at java.lang.reflect.Method.invoke(Method.java:511)
    06-19 16:00:25.279: E/AndroidRuntime(629): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
    06-19 16:00:25.279: E/AndroidRuntime(629): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
    06-19 16:00:25.279: E/AndroidRuntime(629): 	at dalvik.system.NativeStart.main(Native Method)
    06-19 16:00:25.279: E/AndroidRuntime(629): Caused by: java.lang.reflect.InvocationTargetException
    06-19 16:00:25.279: E/AndroidRuntime(629): 	at java.lang.reflect.Method.invokeNative(Native Method)
    06-19 16:00:25.279: E/AndroidRuntime(629): 	at java.lang.reflect.Method.invoke(Method.java:511)
    06-19 16:00:25.279: E/AndroidRuntime(629): 	at android.view.View$1.onClick(View.java:3039)
    06-19 16:00:25.279: E/AndroidRuntime(629): 	... 11 more
    06-19 16:00:25.279: E/AndroidRuntime(629): Caused by: java.lang.NullPointerException
    06-19 16:00:25.279: E/AndroidRuntime(629): 	at android.content.ContextWrapper.getApplicationContext(ContextWrapper.java:101)
    06-19 16:00:25.279: E/AndroidRuntime(629): 	at my.TUBDD.Visites.Clients.sauver(Clients.java:42)
    06-19 16:00:25.279: E/AndroidRuntime(629): 	at my.TUBDD.Visites.TUBDDVisitesActivity.save(TUBDDVisitesActivity.java:22)
    06-19 16:00:25.279: E/AndroidRuntime(629): 	... 14 more

  8. #8
    Membre actif
    Inscrit en
    Décembre 2008
    Messages
    280
    Détails du profil
    Informations forums :
    Inscription : Décembre 2008
    Messages : 280
    Points : 261
    Points
    261
    Par défaut
    Salut,

    Et si tu implémente onClickListener sur ton Activity et que tu ajoute "this" dans le listener de ton bouton ?

    Paye Tes Dettes - Applciation android.

    DevHackSecure - Pense bête d'un étudiant en informatique - Tutos DEV

    " I also realize that _everybody_ thinks that they are right, and that they are supported by all other right-thinking people. That's just how people work. We all think we're better than average." Linus Torvalds

  9. #9
    Nouveau Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2012
    Messages
    11
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2012
    Messages : 11
    Points : 1
    Points
    1
    Par défaut
    Je vais essayer, mais est ce que deja la structure de ma BDD et de ma classe Client ainsi que ma méthode sauver() est correct ?

  10. #10
    Nouveau Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2012
    Messages
    11
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2012
    Messages : 11
    Points : 1
    Points
    1
    Par défaut
    Tu aurais un exemple, car je ne comprends pas trés bien ?

    Tu veux que je fasse un truc dans ce genre ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    View.OnClickListener monClique = new View.OnClickListener() 
        {
     
    	public void onClick(View v) 
    	{
    		// TODO Auto-generated method stub
    		Clients cl = new Clients(1,"TEST");
    		cl.sauver();
    	}
        };

  11. #11
    Expert éminent

    Homme Profil pro
    Ingénieur systèmes et réseaux
    Inscrit en
    Février 2007
    Messages
    4 253
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur systèmes et réseaux
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Février 2007
    Messages : 4 253
    Points : 7 618
    Points
    7 618
    Billets dans le blog
    3
    Par défaut
    Non mais c'est bon... il suffit juste de rajouter un paramètre "View " non utilisé dans la définition de la méthode "save" !
    N'oubliez pas de cliquer sur mais aussi sur si un commentaire vous a été utile !
    Et surtout

  12. #12
    Nouveau Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2012
    Messages
    11
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2012
    Messages : 11
    Points : 1
    Points
    1
    Par défaut
    Comme ceci ?

    Citation Envoyé par ochbob Voir le message
    Bon be j'ai essayé de rajouter les parametre View comme ceci a ma methode save():

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    public void save(View view)
        {
        	Clients cl = new Clients(1,"Urban");
    		cl.sauver();
        }
    Mais l'app plante quand meme apres l'appuie du bouton.

    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
    06-19 16:00:18.022: D/gralloc_goldfish(629): Emulator without GPU emulation detected.
    06-19 16:00:25.202: D/AndroidRuntime(629): Shutting down VM
    06-19 16:00:25.202: W/dalvikvm(629): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
    06-19 16:00:25.279: E/AndroidRuntime(629): FATAL EXCEPTION: main
    06-19 16:00:25.279: E/AndroidRuntime(629): java.lang.IllegalStateException: Could not execute method of the activity
    06-19 16:00:25.279: E/AndroidRuntime(629): 	at android.view.View$1.onClick(View.java:3044)
    06-19 16:00:25.279: E/AndroidRuntime(629): 	at android.view.View.performClick(View.java:3511)
    06-19 16:00:25.279: E/AndroidRuntime(629): 	at android.view.View$PerformClick.run(View.java:14105)
    06-19 16:00:25.279: E/AndroidRuntime(629): 	at android.os.Handler.handleCallback(Handler.java:605)
    06-19 16:00:25.279: E/AndroidRuntime(629): 	at android.os.Handler.dispatchMessage(Handler.java:92)
    06-19 16:00:25.279: E/AndroidRuntime(629): 	at android.os.Looper.loop(Looper.java:137)
    06-19 16:00:25.279: E/AndroidRuntime(629): 	at android.app.ActivityThread.main(ActivityThread.java:4424)
    06-19 16:00:25.279: E/AndroidRuntime(629): 	at java.lang.reflect.Method.invokeNative(Native Method)
    06-19 16:00:25.279: E/AndroidRuntime(629): 	at java.lang.reflect.Method.invoke(Method.java:511)
    06-19 16:00:25.279: E/AndroidRuntime(629): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
    06-19 16:00:25.279: E/AndroidRuntime(629): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
    06-19 16:00:25.279: E/AndroidRuntime(629): 	at dalvik.system.NativeStart.main(Native Method)
    06-19 16:00:25.279: E/AndroidRuntime(629): Caused by: java.lang.reflect.InvocationTargetException
    06-19 16:00:25.279: E/AndroidRuntime(629): 	at java.lang.reflect.Method.invokeNative(Native Method)
    06-19 16:00:25.279: E/AndroidRuntime(629): 	at java.lang.reflect.Method.invoke(Method.java:511)
    06-19 16:00:25.279: E/AndroidRuntime(629): 	at android.view.View$1.onClick(View.java:3039)
    06-19 16:00:25.279: E/AndroidRuntime(629): 	... 11 more
    06-19 16:00:25.279: E/AndroidRuntime(629): Caused by: java.lang.NullPointerException
    06-19 16:00:25.279: E/AndroidRuntime(629): 	at android.content.ContextWrapper.getApplicationContext(ContextWrapper.java:101)
    06-19 16:00:25.279: E/AndroidRuntime(629): 	at my.TUBDD.Visites.Clients.sauver(Clients.java:42)
    06-19 16:00:25.279: E/AndroidRuntime(629): 	at my.TUBDD.Visites.TUBDDVisitesActivity.save(TUBDDVisitesActivity.java:22)
    06-19 16:00:25.279: E/AndroidRuntime(629): 	... 14 more

  13. #13
    Membre régulier
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Janvier 2012
    Messages
    149
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Savoie (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Janvier 2012
    Messages : 149
    Points : 109
    Points
    109
    Par défaut
    j'ai rien dit je sors

  14. #14
    Membre régulier
    Homme Profil pro
    Inscrit en
    Avril 2008
    Messages
    176
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Avril 2008
    Messages : 176
    Points : 106
    Points
    106
    Par défaut
    Salut
    désolé, j'ai pas vu la gestion du onClick , concernant l'erreur je pense qu'il y a une erreur dans l’exécution de la requête SQL, car la table est CLIENT et non CLIENTS

    OK
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     public void save(View view)
        {
        	Clients cl = new Clients(1,"TEST");
    	cl.sauver(view.getContext());
        	
        }

    OK Client il faut juste faire la modif de CLIENTS
    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
    package my.TUBDD.Visites;
     
    import java.sql.Date;
    import java.sql.Time;
    import java.util.Calendar;
     
    import my.TUBDD.Visites.R;
    import my.TUBDD.Visites.SqiliteLocal;
    import android.app.Application;
    import android.content.ContentValues;
    import android.database.Cursor;
    import android.database.SQLException;
    import android.database.sqlite.SQLiteDatabase;
    import android.database.sqlite.SQLiteOpenHelper;
    import android.view.View;
    import android.widget.TextView;
    import android.widget.Toast;
     
    public class Clients extends Application
     
    	{
     
    	 	private int ID;
    	    private String nom;
     
    	    public Clients(int ID, String Nom ) 
    	    {
    	        this.ID = ID;
    	        this.nom = Nom;
    	    }
     
    	    /**
    		 * base de données
    		 */
    		  private SQLiteOpenHelper m_dbHelper;
     
     
    	public void sauver() 
    		{
    		// TODO Auto-generated method stub
    		String mess="Reussi";       
            m_dbHelper = new SqiliteLocal(getApplicationContext());
            SQLiteDatabase db = m_dbHelper.getWritableDatabase();
    		ContentValues values = new ContentValues();
    		//values.put("ID", ID);
    		values.put("NOM", nom);
    		try
    		{
    //		db.insertOrThrow("CLIENTS", null, values); //insertion d'un enregistrement
    db.insertOrThrow("CLIENT", null, values); //insertion d'un enregistrement
    		}
    		catch (SQLException e)
    			{
    				mess ="Erreur insertion";
    			}
    		
    		}
     
     
    }
    je pense qu'il y a aussi un pb avec le toast essayes en mode debug pour voir et aussi testes si ta table est bien crée et aussi l'insertion est bien effectuée
    @++

  15. #15
    Expert éminent

    Homme Profil pro
    Ingénieur systèmes et réseaux
    Inscrit en
    Février 2007
    Messages
    4 253
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur systèmes et réseaux
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Février 2007
    Messages : 4 253
    Points : 7 618
    Points
    7 618
    Billets dans le blog
    3
    Par défaut
    Oui mais là, comme tu peux le constater c'est autre chose:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
     
    06-19 16:00:25.279: E/AndroidRuntime(629): Caused by: java.lang.NullPointerException
    06-19 16:00:25.279: E/AndroidRuntime(629): 	at android.content.ContextWrapper.getApplicationContext(ContextWrapper.java:101)
    06-19 16:00:25.279: E/AndroidRuntime(629): 	at my.TUBDD.Visites.Clients.sauver(Clients.java:42)
    N'oubliez pas de cliquer sur mais aussi sur si un commentaire vous a été utile !
    Et surtout

  16. #16
    Membre régulier
    Homme Profil pro
    Inscrit en
    Avril 2008
    Messages
    176
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Avril 2008
    Messages : 176
    Points : 106
    Points
    106
    Par défaut
    c'est logique d'avoir cette erreur, le context de l'application n'est pas transmis :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    public void save(View view)
        {
        	Clients cl = new Clients(1,"TEST");
    	cl.sauver(view.getContext());
        	
        }
    Et puis réception du context
    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 sauver(Context context) 
    		{
    		// TODO Auto-generated method stub
    		String mess="Reussi";       
            m_dbHelper = new SqiliteLocal(context);
            SQLiteDatabase db = m_dbHelper.getWritableDatabase();
    		ContentValues values = new ContentValues();
    		//values.put("ID", ID);
    		values.put("NOM", nom);
    		try
    		{
    //		db.insertOrThrow("CLIENTS", null, values); //insertion d'un enregistrement
    db.insertOrThrow("CLIENT", null, values); //insertion d'un enregistrement
    		}
    		catch (SQLException e)
    			{
    				mess ="Erreur insertion";
    			}
    		
    		}

  17. #17
    Nouveau Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2012
    Messages
    11
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2012
    Messages : 11
    Points : 1
    Points
    1
    Par défaut
    merci pour vos réponse alors j'ai pas tester le mode debug, car je ne sais pas trop l'utiliser

    J'ai essayer de voir la creation de la table mais il n'y a rien :/

    Je test la methode de megalopex.

  18. #18
    Nouveau Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2012
    Messages
    11
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2012
    Messages : 11
    Points : 1
    Points
    1
    Par défaut
    C'etait bien ça, je n'ai plus de plantage et lorsque je vérifie dans l'adb avec mes requête SQL le nom apparait correctement.

    Tu pourrais m'expliquer en soit pourquoi cela ne marchait pas ?

    Et par contre en effet mon toast a un soucis, car quand je le décommente l'app plante.
    Je pense que c'est un soucis avec le getApplicationContext non ? Mais je ne sais pas trop quoi modifier :/

    En tout cas je vous remercie deja pour mon premier probleme

  19. #19
    Nouveau Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2012
    Messages
    11
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2012
    Messages : 11
    Points : 1
    Points
    1
    Par défaut
    J'essaye a présent d'afficher ma table dans un TextView apres clique sur le bouton "Afficher".

    J'ai donc creer un textview que j'ai appeler textAff.

    il y a un onclick sur mon nouveau bouton appeler show()

    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
    package my.TUBDD.Visites;
     
     
     
     
    import android.app.Activity;
    import android.content.Context;
    import android.database.Cursor;
    import android.database.sqlite.SQLiteDatabase;
    import android.database.sqlite.SQLiteOpenHelper;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.TextView;
     
    public class TUBDDVisitesActivity extends Activity 
    {
    	private SQLiteOpenHelper m_dbHelper;
    	private TextView extView;
     
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) 
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
     
            extView = (TextView) findViewById(R.id.TexteAff);  
     
     
        }
     
     
    	public void save(View view) 
    	{
    		// TODO Auto-generated method stub
    		Clients cl = new Clients(1,"Urban");
    		cl.sauver(view.getContext());
    	}
     
    	public void show(View view) 
    	{		  
    		    	// ouverture en mode lecture
    		    	 SQLiteDatabase db = m_dbHelper.getReadableDatabase();
    		    	 // lecture de la table CLIENT
    		    	 String [] champs={"ID","NOM"};
    		    	 //equivalent requete select * from STOCK
    		    	 Cursor cur = db.query("CLIENT",champs, null, null, null, null, null);
     
    		    	        cur.moveToFirst(); //on se placce sur le premier element
    		    	        extView.setText(""); //efface le texte
    		    	        while (cur.isAfterLast() == false) 
    		    	        {
    		    	        	extView.append("\n" + cur.getString(0)+" "+ cur.getString(1)+" "+ cur.getString(2));
    		    	       	    cur.moveToNext();
    		    	        }
    		    	        // fermeture du cursor
    		    	        cur.close(); 	    
     
    	}
     
     
    }
    Mais cela ne marche pas :/

    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
    06-21 15:17:08.970: D/gralloc_goldfish(1291): Emulator without GPU emulation detected.
    06-21 15:17:45.000: D/AndroidRuntime(1291): Shutting down VM
    06-21 15:17:45.000: W/dalvikvm(1291): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
    06-21 15:17:45.080: E/AndroidRuntime(1291): FATAL EXCEPTION: main
    06-21 15:17:45.080: E/AndroidRuntime(1291): java.lang.IllegalStateException: Could not execute method of the activity
    06-21 15:17:45.080: E/AndroidRuntime(1291): 	at android.view.View$1.onClick(View.java:3044)
    06-21 15:17:45.080: E/AndroidRuntime(1291): 	at android.view.View.performClick(View.java:3511)
    06-21 15:17:45.080: E/AndroidRuntime(1291): 	at android.view.View$PerformClick.run(View.java:14105)
    06-21 15:17:45.080: E/AndroidRuntime(1291): 	at android.os.Handler.handleCallback(Handler.java:605)
    06-21 15:17:45.080: E/AndroidRuntime(1291): 	at android.os.Handler.dispatchMessage(Handler.java:92)
    06-21 15:17:45.080: E/AndroidRuntime(1291): 	at android.os.Looper.loop(Looper.java:137)
    06-21 15:17:45.080: E/AndroidRuntime(1291): 	at android.app.ActivityThread.main(ActivityThread.java:4424)
    06-21 15:17:45.080: E/AndroidRuntime(1291): 	at java.lang.reflect.Method.invokeNative(Native Method)
    06-21 15:17:45.080: E/AndroidRuntime(1291): 	at java.lang.reflect.Method.invoke(Method.java:511)
    06-21 15:17:45.080: E/AndroidRuntime(1291): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
    06-21 15:17:45.080: E/AndroidRuntime(1291): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
    06-21 15:17:45.080: E/AndroidRuntime(1291): 	at dalvik.system.NativeStart.main(Native Method)
    06-21 15:17:45.080: E/AndroidRuntime(1291): Caused by: java.lang.reflect.InvocationTargetException
    06-21 15:17:45.080: E/AndroidRuntime(1291): 	at java.lang.reflect.Method.invokeNative(Native Method)
    06-21 15:17:45.080: E/AndroidRuntime(1291): 	at java.lang.reflect.Method.invoke(Method.java:511)
    06-21 15:17:45.080: E/AndroidRuntime(1291): 	at android.view.View$1.onClick(View.java:3039)
    06-21 15:17:45.080: E/AndroidRuntime(1291): 	... 11 more
    06-21 15:17:45.080: E/AndroidRuntime(1291): Caused by: java.lang.NullPointerException
    06-21 15:17:45.080: E/AndroidRuntime(1291): 	at my.TUBDD.Visites.TUBDDVisitesActivity.show(TUBDDVisitesActivity.java:43)
    06-21 15:17:45.080: E/AndroidRuntime(1291): 	... 14 more
    PS: je n'ai rien modifier d'autre.

  20. #20
    Membre régulier
    Homme Profil pro
    Inscrit en
    Avril 2008
    Messages
    176
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Avril 2008
    Messages : 176
    Points : 106
    Points
    106
    Par défaut
    Salut
    voici une réponse à ta question, en espérant avoir pu t'aider @++

Discussions similaires

  1. Réponses: 2
    Dernier message: 28/02/2012, 19h08
  2. LinkButton créé sur à un Click event d'un Bouton
    Par Poussy-Puce dans le forum ASP.NET
    Réponses: 2
    Dernier message: 26/12/2007, 13h07
  3. Probleme sur le click d'un bouton
    Par kam81 dans le forum Applets
    Réponses: 0
    Dernier message: 12/12/2007, 08h52
  4. Afficher des champs sur base d'un click d'un bouton radio
    Par marxan dans le forum Coldfusion
    Réponses: 1
    Dernier message: 31/05/2007, 19h22
  5. Action automatique sur click d'un bouton de formulaire
    Par ned-flanders dans le forum Langage
    Réponses: 7
    Dernier message: 20/03/2007, 16h37

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