Erreur

Fermé
ikhlass90 Messages postés 5 Date d'inscription lundi 25 février 2013 Statut Membre Dernière intervention 10 mars 2013 - 27 févr. 2013 à 15:52
Bonjour, pourquoi lorsque je lance mon application android il m'affiche mon url
voila le code
package com.prod.testproduit;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
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.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.LinearLayout;
import android.widget.TextView;

public class MainActivity extends Activity {
TextView txt;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

LinearLayout rootLayout = new LinearLayout(getApplicationContext());
txt = new TextView(getApplicationContext());
rootLayout.addView(txt);
setContentView(rootLayout);

txt.setText("Connexion...");
txt.setText(getServerData(strURL));
}


public static final String strURL = "http://192.168.1.6/test/test.php";

private String getServerData(String returnString) {
InputStream is = null;
String result = "";

ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();



try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(strURL);
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();

}catch(Exception e){
Log.e("log_tag", "Error in http connection " + e.toString());
}


try{
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result=sb.toString();
}catch(Exception e){
Log.e("log_tag", "Error converting result " + e.toString());
}

try{
JSONArray jArray = new JSONArray(result);
for(int i=0;i<jArray.length();i++){
JSONObject json_data = jArray.getJSONObject(i);
Log.i("log_tag","id_produit: "+json_data.getInt("id_produit")+
", titre_produit: "+json_data.getString("titre_produit")
);
returnString += "\n\t" + jArray.getJSONObject(i);
}
}catch(JSONException e){
Log.e("log_tag", "Error parsing data " + e.toString());
}
return returnString;
}
}
et voila le code php
<?php
header('Content-type=application/json; charset=utf-8');
mysql_connect("localhost","root","root");
mysql_select_db("pragmacom_site");
$sql=mysql_query("select id_produit,titre_produit from produit");
while($row=mysql_fetch_assoc($sql))
$output[]=$row;
print(json_encode($output));
mysql_close();
?>
et voila l'erreur dans le logcat:

02-27 14:44:49.198: E/log_tag(274): Error parsing data org.json.JSONException: Value <!DOCTYPE of type java.lang.String cannot be converted to JSONArray