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 :

classe java ne marche pas


Sujet :

Android

  1. #1
    Futur Membre du Club
    Homme Profil pro
    Auditeur informatique
    Inscrit en
    Juin 2017
    Messages
    10
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 31
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Auditeur informatique

    Informations forums :
    Inscription : Juin 2017
    Messages : 10
    Points : 7
    Points
    7
    Par défaut classe java ne marche pas
    Salut les amis ,
    je suis entrain de faire une application...j'ai fait une classe java qui relie android avec base données en utilisant JSON
    j'ai tester cette classe avec les edit text et ça marche et les valeurs sont ajouté a la base...mais quand j'ai mis les bouttons radio ça marche pas et l'application se ferme sans aucune erreur

    voiçi Mon classe java

    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
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    import android.os.AsyncTask;
    import android.os.Bundle;
    import android.support.v7.app.AppCompatActivity;
    import android.util.Log;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.RadioButton;
    import android.widget.RadioGroup;
    import android.widget.Toast;
     
    import org.json.JSONObject;
     
    import java.util.HashMap;
     
     
    public class adddddd extends AppCompatActivity{
        private EditText vitesse,satisfactionnombredevoies,satisfactionnaturederoute,niveauxvisibilite,gravitedeevenementanormal;
        String aa,bb,cc,dd,ee,ff,gg,hh,ii;
        private Button bt;
        private RadioGroup nombredevoies,naturederoute,visibilite,evenementanormal;
     
     
     
     
     
        @Override
     
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.adddd);
     
            /*FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab1);
            fab.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#00DDFF")));*/
            //String strmatricule,strcar_type,str_car_description;
            vitesse = (EditText) findViewById(R.id.vitesse);
            nombredevoies = (RadioGroup) findViewById(R.id.nombredevoies);
            naturederoute = (RadioGroup) findViewById(R.id.naturederoute);
            visibilite = (RadioGroup) findViewById(R.id.visibilite);
            evenementanormal = (RadioGroup) findViewById(R.id.evenementanormal);
            bt = (Button) findViewById (R.id.bt);
            satisfactionnombredevoies = (EditText) findViewById(R.id.satisfactionnombredevoies);
            satisfactionnaturederoute = (EditText) findViewById(R.id.satisfactionnaturederoute);
            niveauxvisibilite = (EditText) findViewById(R.id.niveauxvisibilite);
            gravitedeevenementanormal = (EditText) findViewById(R.id.gravitedeevenementanormal);
     
     
            //alert   =   (TextView)  findViewById(R.id.alert_textView);
     
            //checkLogin();
     
            // insert /update a part in a table
            bt.setOnClickListener(
                    new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
     
     
     
                            aa = vitesse.getText().toString();
                            bb =((RadioButton)findViewById(nombredevoies.getCheckedRadioButtonId())).getText().toString();
                            cc = ((RadioButton)findViewById(naturederoute.getCheckedRadioButtonId())).getText().toString();
                            dd = ((RadioButton)findViewById(visibilite.getCheckedRadioButtonId())).getText().toString();
                            ee = ((RadioButton)findViewById(evenementanormal.getCheckedRadioButtonId())).getText().toString();
                            ff = satisfactionnombredevoies.getText().toString();
                            gg = satisfactionnaturederoute.getText().toString();
                            hh = niveauxvisibilite.getText().toString();
                            ii = gravitedeevenementanormal.getText().toString();
                            //Log.i("matricule",""+strmatricule);
                            //Log.i("car_type",""+strcar_type);
                            //Log.i("car_description",""+strcar_description);
                            new AsyncTask<String, Void, String>() {
     
                                private JSONObject jsonObject;
                                @Override
                                protected String doInBackground(String... arg0) {
     
     
                                    JSONParser jParser = new JSONParser();
     
                                    String s;
     
     
                                    HashMap<String, String> param = new HashMap<>();
                                    //Log.i("hhhhhh", strmatricule+"gg"+strcar_description+"ff"+strcar_type);
                                    param.put("vitesse", aa);
                                    param.put("nombredevoies", bb);
                                    param.put("naturederoute", cc);
                                    param.put("visibilite", dd);
                                    param.put("evenementanormal", ee);
                                    param.put("satisfactionnombredevoies", ff);
                                    param.put("satisfactionnaturederoute", gg);
                                    param.put("niveauxvisibilite", hh);
                                    param.put("gravitedeevenementanormal", ii);
     
     
     
                                    try {
     
                                        jsonObject = jParser.makeHttpRequest("http://10.0.2.2/addddd/addd.php", "POST", param);
     
                                        s = jsonObject.toString();
                                        Log.i("jsonObject", s);
     
                                    } catch (Exception e) {
     
                                        s = "{'done':'failed'}";
                                    }
     
     
                                    return s;
     
                                }
     
                                @Override
                                protected void onPostExecute(String result) {
                                    super.onPostExecute(result);
                                    JSONObject js;
                                    try {
     
                                        js = new JSONObject(result);
     
                                        String done = js.getString("done");
     
                                        if (done.equals("success"))
                                        {
                                            Toast.makeText(getApplicationContext(), "success DB !", Toast.LENGTH_SHORT).show();
     
                                        }
                                        if (done.equals("failed")) {
                                            Toast.makeText(getApplicationContext(), "Updating DB failed !", Toast.LENGTH_SHORT).show();
                                        }
     
     
     
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }
     
     
                                }
     
                            }.execute();
     
                        }
                    }
            );
     
        }}

    Mon Xml

    Code xml : 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
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
     
        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1">
     
     
     
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical" >
     
                <TextView
                    android:id="@+id/o"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="Saisir Votre Vitesse" />
     
                <EditText
                    android:id="@+id/editText"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:ems="10"
                    />
     
                <TextView
                    android:id="@+id/textView9"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Saisir Le nombre de voies" />
     
                <RadioGroup
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:id="@+id/nombredevoies">
     
                    <RadioButton
                        android:id="@+id/seule"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:text="seule Voie" />
     
                    <RadioButton
                        android:id="@+id/deux"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:text="deux voies" />
     
                    <RadioButton
                        android:id="@+id/Trois"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:text="Trois voies" />
     
                </RadioGroup>
     
                <TextView
                    android:id="@+id/textView11"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="nature de route" />
     
                <RadioGroup
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/naturederoute">
     
                    <RadioButton
                        android:id="@+id/route"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:text="route" />
     
                    <RadioButton
                        android:id="@+id/artere"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:text="artère interurbaine" />
     
                    <RadioButton
                        android:id="@+id/autoroute"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:text="autoroute" />
                </RadioGroup>
     
                <TextView
                    android:id="@+id/textView12"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="visibilité" />
     
                <RadioGroup
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:id="@+id/visibilite">
     
                    <RadioButton
                        android:id="@+id/bonne"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:text="bonne" />
     
                    <RadioButton
                        android:id="@+id/mauvaise"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:text="mauvise" />
                </RadioGroup>
     
                <TextView
                    android:id="@+id/textView13"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="événement anormal" />
     
                <RadioGroup
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:id="@+id/evenementanormal">
     
                    <RadioButton
                        android:id="@+id/existe"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:text="Oui" />
     
                    <RadioButton
                        android:id="@+id/non"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:text="Non" />
                </RadioGroup>
     
                <TextView
                    android:id="@+id/satisfactbredevoies"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="precisez votre satisfaction de nombre de voies" />
     
                <EditText
                    android:id="@+id/satisfactionnombredevoies"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:ems="10"
                    android:inputType="textPersonName"
                    android:hint="valeur entre 0 et 100" />
     
                <TextView
                    android:id="@+id/hh"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="satisfaction de la nature de route" />
     
                <EditText
                    android:id="@+id/satisfactionnaturederoute"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:ems="10"
                    android:inputType="textPersonName"
                    android:hint="valeur entre 0 et 100" />
     
                <TextView
                    android:id="@+id/hhh"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="niveaux de visibilité" />
     
                <EditText
                    android:id="@+id/niveauxvisibilite"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:ems="10"
                    android:inputType="textPersonName"
                    android:hint="valeur entre 0 et 100" />
     
                <TextView
                    android:id="@+id/hhhhh"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="gravité de l'évenement anormal" />
     
                <EditText
                    android:id="@+id/gravitedeevenementanormal"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:ems="10"
                    android:inputType="textPersonName"
                    android:hint="valeur entre 0 et 100" />
     
                <Button
                    android:id="@+id/bt"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="envoyer" />
            </LinearLayout>
     
     
     
        </ScrollView>
     
    </LinearLayout>

  2. #2
    Membre habitué
    Homme Profil pro
    Développeur COBOL
    Inscrit en
    Janvier 2003
    Messages
    339
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur COBOL
    Secteur : Finance

    Informations forums :
    Inscription : Janvier 2003
    Messages : 339
    Points : 184
    Points
    184
    Par défaut
    Salut

    Je ne comprend pas bien le besoin. Tu cherches à relier ta variable nombrevoies (entre autres) déclaré en type "RadioButton" avec un élément de ton layout de type "EditText"

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    private RadioGroup nombredevoies,naturederoute,visibilite,evenementanormal;
    nombredevoies = (RadioGroup) findViewById(R.id.nombredevoies);
    
    <EditText
    android:id="@+id/nombredevoies"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ems="10"
    android:inputType="textPersonName"
    android:text="Name" />
    
    Je ne penses pas que cela puisse marcher ...
    « Ne me faites pas d'objections.
    Les difficultés en feront assez d'elles-mêmes. »

    sir Winston Churchill

  3. #3
    Futur Membre du Club
    Homme Profil pro
    Auditeur informatique
    Inscrit en
    Juin 2017
    Messages
    10
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 31
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Auditeur informatique

    Informations forums :
    Inscription : Juin 2017
    Messages : 10
    Points : 7
    Points
    7
    Par défaut
    Non monsieur , j'ai des entrées de type edittext te des entrées de type boutton
    je veux que si je clique sur le boutton Oui par exemple ça va etre enregistrer dans un String et envoyer vers la base de données.j'ai travailler avec juste les edittext et k'ai ecrit des valeurs et les mettre dans un String et les envoyé et ça marche.mais quand j'ai voulu avoir un boutton dont l'utilisateur clique sur un boutton (pour mieux organisé l'application donc l'utilisateur n'ecrit pas tout les données just il clique )ça marche pas..Merci d'avance

  4. #4
    Membre habitué
    Homme Profil pro
    Développeur COBOL
    Inscrit en
    Janvier 2003
    Messages
    339
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur COBOL
    Secteur : Finance

    Informations forums :
    Inscription : Janvier 2003
    Messages : 339
    Points : 184
    Points
    184
    Par défaut
    Sauf erreur de ma part, dans ton layout, il n'y a aucun RadioButton alors que ton code java en appel ....

    Ou alors il manque du code que tu n'as pas montré !
    « Ne me faites pas d'objections.
    Les difficultés en feront assez d'elles-mêmes. »

    sir Winston Churchill

  5. #5
    Futur Membre du Club
    Homme Profil pro
    Auditeur informatique
    Inscrit en
    Juin 2017
    Messages
    10
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 31
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Auditeur informatique

    Informations forums :
    Inscription : Juin 2017
    Messages : 10
    Points : 7
    Points
    7
    Par défaut
    Désolé, c'est ma faute : j'avais copié un autre xml. C'est bon j'ai changé le xml dans la publication.

    il m'a affiché comme erreur : attempt to invoke virtual method'android.text.editable android .widget.editTtext.getTtext()' on a null object reference.

Discussions similaires

  1. Création d'une "class" en matlab=>marche pas !
    Par morpheusmg dans le forum MATLAB
    Réponses: 5
    Dernier message: 03/03/2011, 18h26
  2. Réponses: 2
    Dernier message: 04/08/2009, 09h55
  3. evenement en java ne marche pas
    Par jasminrose dans le forum Débuter avec Java
    Réponses: 3
    Dernier message: 09/06/2008, 12h11
  4. classe images ne marche pas
    Par khadir dans le forum Mise en page CSS
    Réponses: 4
    Dernier message: 15/10/2007, 16h58
  5. class qui ne marche pas
    Par RaphAstronome dans le forum Langage
    Réponses: 3
    Dernier message: 26/05/2006, 20h00

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