Hello I have an error with my code which tells me org.json.JSONException end of input at character 0 of when I try to recover my json on the printers, normally this error occurs that its returns an empty string but I do not see Not what ...
Here is my code:
public class MaterielAssocie extends Activity {
private ListView lv;
public static etablissement etabSELECT;
private ProgressDialog progressDialog;
public static ArrayListdetail = new ArrayList<>();
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.materiel_associe);
lv = (ListView) findViewById(R.id.listViewMa);
chargerJeuDessaie();
rafraichirListView();
}
private void chargerJeuDessaie()
{
progressDialog = progressDialog.show(this,"Gestion des services associés","Telechargement en cours");
MonAsyncTaskHttp monAsyncTaskHttp = new MonAsyncTaskHttp() {
@Override
protected void onPostExecute(Object o) {
super.onPostExecute(o);
MaterielAssocie.detail.clear();
try {
JSONArray jsonArray = new JSONArray(o.toString());
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
imprimante imp = imprimante.factoryImp(jsonObject);
MaterielAssocie.detail.add(imp);
rafraichirListView();
}
} catch (JSONException e) {
e.printStackTrace();
}
progressDialog.dismiss();
}
};
monAsyncTaskHttp.execute("requete=getLesImprimantes=" + search_ville.etabSELECT.getId());
}
public void rafraichirListView() {
ArrayAdapter imprimanteadapter = new ArrayAdapter(MaterielAssocie.this, android.R.layout.simple_list_item_1, detail);
lv.setAdapter(imprimanteadapter);
}
here is my code of my page printer :
public class imprimante extends Activity {
private int id_imprimante;
private String marque_imprimante;
private String emplacement;
private int ref_etab;
public imprimante(int id_imprimante, String marque_imprimante, String emplacement, int ref_etab) {
this.id_imprimante = id_imprimante;
this.marque_imprimante = marque_imprimante;
this.emplacement = emplacement;
this.ref_etab = ref_etab;
}
public int getId_imprimante() {
return id_imprimante;
}
public void setId_imprimante(int id_imprimante) {
this.id_imprimante = id_imprimante;
}
public String getMarque_imprimante() {
return marque_imprimante;
}
public void setMarque_imprimante(String marque_imprimante) {
this.marque_imprimante = marque_imprimante;
}
public String getEmplacement() {
return emplacement;
}
public void setEmplacement(String emplacement) {
this.emplacement = emplacement;
}
public int getRef_etab() {
return ref_etab;
}
public void setRef_etab(int ref_etab) {
this.ref_etab = ref_etab;
}
public String toString() {
String lib = ""+ marque_imprimante +" "+ emplacement +"";
return lib;
}
public static imprimante factoryImp(JSONObject jo)
{
imprimante imp = null;
try {
int id_imprimante = jo.getInt("id_imprimante");
String marque_imprimante = jo.getString("marque_imprimante");
String emplacement = jo.getString("emplacement");
int ref_etab = jo.getInt("ref_etab");
imp = new imprimante(id_imprimante,marque_imprimante,emplacement,ref_etab);
} catch (JSONException e) {
e.printStackTrace();
}
return imp;
}
}
If someone sees the error I do not see thank you
errors :
W/System.err: org.json.JSONException: End of input at character 0 of
04-26 14:51:33.025 24113-24113/ddec.applicationddec W/System.err: at org.json.JSONTokener.syntaxError(JSONTokener.java:450)
04-26 14:51:33.025 24113-24113/ddec.applicationddec W/System.err: at org.json.JSONTokener.nextValue(JSONTokener.java:97)
04-26 14:51:33.025 24113-24113/ddec.applicationddec W/System.err: at org.json.JSONArray.(JSONArray.java:87)
04-26 14:51:33.025 24113-24113/ddec.applicationddec W/System.err: at org.json.JSONArray.(JSONArray.java:103)
04-26 14:51:33.025 24113-24113/ddec.applicationddec W/System.err: at ddec.applicationddec.MaterielAssocie$1.onPostExecute(MaterielAssocie.java:43)
04-26 14:51:33.025 24113-24113/ddec.applicationddec W/System.err: at
android.os.AsyncTask.finish(AsyncTask.java:631)
04-26 14:51:33.025 24113-24113/ddec.applicationddec W/System.err: at android.os.AsyncTask.access$600(AsyncTask.java:177)
04-26 14:51:33.025 24113-24113/ddec.applicationddec W/System.err: at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
04-26 14:51:33.025 24113-24113/ddec.applicationddec W/System.err: at android.os.Handler.dispatchMessage(Handler.java:99)
JSON String
{
"type": "object",
"properties": {
"id_imprimante": {
"type": "int"
},
"marque_imprimante": {
"type": "String"
},
"emplacement": {
"type": "String"
},
"ref_etab": {
"type": "int"
},
}
}