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>
Partager