Bonjour,

j'ai développé une application qui permet de récupérer une liste d'exploitations après avoir saisi une CIN, le problème c'est que la liste ne s'affiche pas sur l'émulateur !!
MainActivity :
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
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
package com.example.rech_exploi;
 
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
 
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
 
import android.app.AlertDialog;
import android.app.ListActivity;
import android.app.ProgressDialog;
import android.net.ParseException;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
 
import com.example.rech_exploi.MonAdapteur.MonAdapteurListener;
 
public class MainActivity extends ListActivity implements MonAdapteurListener{
	Button btnRechercher;
	TextView txtMsg;
	EditText edtMsg;
	JSONObject json_data=null;
	HttpResponse response=null;
	//ArrayList<String> donnees = new ArrayList<String>();
	ArrayList<Exploitation> exploitations = new ArrayList<Exploitation>();
	private ProgressDialog progressDialog;
 
 
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		progressDialog = new ProgressDialog(MainActivity.this);
 
		btnRechercher = (Button)findViewById(R.id.btnRechercher);
		edtMsg = (EditText) findViewById(R.id.edtMsg);
 
	}
	public void onClickNom(Exploitation item, final int position) {
		android.app.AlertDialog.Builder builder = new AlertDialog.Builder(this);
		builder.setIcon(R.drawable.icon);
		builder.setTitle("Exploitation");
 
		builder.setMessage("Vous avez cliqué sur : " + item.nom);
		builder.setNegativeButton("Non", null);
		builder.setPositiveButton("Oui", null);
		/*builder.setPositiveButton("Oui",new android.content.DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int arg1) {
				Toast.makeText(this,"id"+exploitations.get(position).id, Toast.LENGTH_SHORT).show();
			}
		}
	);*/
		builder.show(); 
	}
 
 
 
	public void Rechercher(View v){
		new asynchtask().execute();        
	}		
 
 
 
 
 
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}
 
 
	class asynchtask extends AsyncTask<Void, Void, Void>{
 
		@Override
		protected void onPreExecute() {
			super.onPreExecute();
			exploitations.clear();
			progressDialog.setMessage("Chargement en cours");
			progressDialog.show();
		}
 
		@Override
		protected Void doInBackground(Void... arg0) {
 
 
			StringBuffer sb = new StringBuffer("");
			BufferedReader br = null;
			try{
				HttpClient client = new DefaultHttpClient();
				HttpPost post = new HttpPost("http://10.0.2.2/webService/Recherche.php");
				String CIN = edtMsg.getText().toString();
				if(CIN.length() > 0){
					try{
						List<NameValuePair> donnees = new ArrayList<NameValuePair>(1);
						donnees.add(new BasicNameValuePair("message", CIN));
						post.setEntity(new UrlEncodedFormEntity(donnees));
					    response = client.execute(post);
						//edtMsg.setText("");
						//Toast.makeText(MainActivity.this, "CIN envoyé!", Toast.LENGTH_SHORT).show();
					    Log.e("", "CIN envoye");
					}
					catch(ClientProtocolException e){
						e.printStackTrace();
					}
					catch(IOException e){
						e.printStackTrace();
					}
				}
				else
					Toast.makeText(MainActivity.this,"Ce champ ne peut etre vide!", Toast.LENGTH_SHORT).show();
				InputStream is = response.getEntity().getContent();
				br = new BufferedReader(new InputStreamReader(is));
				String ligneLue = br.readLine();
				while(ligneLue !=null){
					sb.append(ligneLue);
					sb.append("\n");
					ligneLue = br.readLine();
				}
 
 
 
				//Toast.makeText(MainActivity.this, sb+" result", Toast.LENGTH_SHORT).show();
 
 
			}
 
 
			catch(Exception e){
				e.printStackTrace();
 
				//Log.e("exception", e.getMessage());
 
				Toast.makeText(MainActivity.this, "une erreur est survenue"+e.getMessage(), Toast.LENGTH_SHORT).show();
			}
			finally{
				if(br !=null){
					try{
						br.close();
					}catch(IOException e){
						e.printStackTrace();
						Log.e("exception", e.getMessage());
						Toast.makeText(MainActivity.this, "une erreur grave est survenue", Toast.LENGTH_SHORT).show();
 
					}
				}
			}
 
 
			try{
		          JSONArray jArray = new JSONArray(sb.toString());
 
		             for(int i=0;i<jArray.length();i++)
		             {
 
		                   json_data = jArray.getJSONObject(i);
		                   //donnees.add(json_data.getString("CIN"));
		                   //donnees.add(json_data.getString("exploit"));
		                   exploitations.add(new Exploitation(json_data.getInt("id"),json_data.getString("Nom"), json_data.getString("adr")));
 
		               }
 
		            }
		            catch(JSONException e){
		             Log.i("tagjsonexp",""+e.toString());
		            } catch (ParseException e) {
		             Log.i("tagjsonpars",""+e.toString());
		       }
 
 
			return null;
		}
 
		@Override
		protected void onPostExecute(Void result) {
			if (progressDialog.isShowing()) {
				progressDialog.dismiss();
            }
 
			ListView list = (ListView) MainActivity.this.findViewById(android.R.id.list);
			MonAdapteur adpt = new MonAdapteur(getApplicationContext(),exploitations);
			adpt.addListener(MainActivity.this);
 
	        list.setAdapter(adpt);
 
			//setListAdapter(new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_expandable_list_item_1, donnees));
            edtMsg.setText("");
			super.onPostExecute(result);
			Log.e("asynchtask", "fin");
		}
 
	}
 
}
MonAdapteur
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
package com.example.rech_exploi;
 
import java.util.ArrayList;
 
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
 
public class MonAdapteur extends BaseAdapter {
 
	private ArrayList<Exploitation> exploitations;
	private LayoutInflater myInflater;
	private Context context;
 
	public MonAdapteur (Context context, ArrayList<Exploitation> _exploitations)
	{
		this.myInflater = LayoutInflater.from(context);
		this.exploitations = _exploitations;
		this.context=context;
	}
 
	@Override
	public int getCount() {
		return this.exploitations.size();
	}
 
	@Override
	public Object getItem(int arg0) {
		return this.exploitations.get(arg0);
	}
 
	@Override
	public long getItemId(int position) {
		return position;
	}
 
	public static class ViewHolder {
		TextView text01;
		TextView text02;
		ImageView image;
	}
 
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
     ViewHolder holder;
 
		if (convertView == null)
		{
			convertView = myInflater.inflate(R.layout.listitem, null);
			holder = new ViewHolder();
			holder.text01 = (TextView) convertView.findViewById(R.id.txtNom);
			holder.text02 = (TextView) convertView.findViewById(R.id.txtDetail);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
 
		holder.text01.setText(exploitations.get(position).nom);
		holder.text02.setText(exploitations.get(position).detail);
 
		holder.image=(ImageView) convertView.findViewById(R.id.icone);
		holder.image.setTag(position);
		holder.image.setOnClickListener(new OnClickListener() {
 
			@Override
			public void onClick(View v) {
				Integer position = (Integer)v.getTag();
				Intent intent = new Intent(context,AndroidGPSTrackingActivity.class);
				intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
				intent.putExtra("nom", exploitations.get(position).nom);
				intent.putExtra("detail", exploitations.get(position).detail);
				intent.putExtra("id", exploitations.get(position).id);
				context.startActivity(intent);
				//Toast.makeText(context,"id"+exploitations.get(position).id, Toast.LENGTH_SHORT).show();
				//sendListener(exploitations.get(position), position);
			}
        });
 
 
		return convertView;
 
		//this.exploitations.clear();
		//((BaseAdapter)list.getAdapter()).notifyDataSetChanged();
 
 
	}
 
    // le mécanisme pour gérer l'ajout de listener sur notre adapter
 
    //Contient la liste des listeners
 
	private ArrayList<MonAdapteurListener> mListListener = new ArrayList<MonAdapteurListener>();
 
	//Pour ajouter un listener sur notre adapter
    public void addListener( MonAdapteurListener aListener) {
    	mListListener.add(aListener);
    }
    private void sendListener(Exploitation item, int position) {
    	for(int i = mListListener.size()-1; i >= 0; i--) {
    		mListListener.get(i).onClickNom(item, position);
    	}
    }
 
	//Interface pour écouter les évènements sur le nom d'une personne
 
   public interface MonAdapteurListener {
   	public void onClickNom(Exploitation item, int position);
   }
}
Exploitation
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
package com.example.rech_exploi;
 
public class Exploitation {
	int id;
	String nom;
	String detail;
 
	public Exploitation (int _id,String _nom, String _detail)
	{
		id =_id;
		nom = _nom;
		detail = _detail;
	}
}
Voici le web service
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
 
<?php
 
if(isset($_POST) && !empty($_POST)){
		$rec=$_POST['message'];
		try{
			//include('conf.ini.php');
			$connexion = new PDO('mysql:host=localhost;dbname=test3','root','');	
			$req = $connexion->query("SELECT id,Nom,adr FROM exploitations WHERE CIN='".$rec."'");
			 while($donnees=$req->fetch()){
					$output[]=$donnees;
					$CIN=$donnees['id'];
					$exploitation=$donnees['Nom'];
					$adr=$donnees['adr'];
		}
 
			print(json_encode($output));
 
	}
	catch (Exception $e){
						die('Erreur : ' .$e->getMessage());
					}
		}
		else echo "veuillez entrez votre CIN";
 
?>
et voici l'erreur qu'affiche le logCat:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
09-24 15:36:36.755: W/EGL_emulation(2160): eglSurfaceAttrib not implemented
09-24 15:36:37.927: E/(2160): CIN envoye
09-24 15:36:38.165: I/tagjsonexp(2160): org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONArray
09-24 15:36:38.484: E/asynchtask(2160): fin
Merci d'avance!