I'm doing an AsyncTask that works I might add if I lower my sdk to 22.
on sdk 23 it doesn't work at all, and even in 22, it scribes some lines for me.
what am i doing wrong ? or how to correct it so that i could run it at sdk 23 ?
@Override
protected Boolean doInBackground(String... urls) {
try {
//------------------>>
HttpGet httppost = new HttpGet(urls[0]);
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(httppost);
// StatusLine stat = response.getStatusLine();
int status = response.getStatusLine().getStatusCode();
if (status == 200) {
HttpEntity entity = response.getEntity();
String data = EntityUtils.toString(entity);
JSONObject jsono = new JSONObject(data);
//this gets us the actors node and puts it in jarray veriable
JSONArray jarray = jsono.getJSONArray("actors");
for (int i = 0; i < jarray.length(); i++) {
//the object veriable will be the node in position i inside the "actors" node in the main json
JSONObject object = jarray.getJSONObject(i);
Log.d("myAppLog", "next one is: ");
Log.d("myAppLog", object.getString("name"));
actorClass actorClassVeriable = new actorClass();
actorClassVeriable.setName(object.getString("name"));
actorClassVeriable.setDescription(object.getString("description"));
actorClassVeriable.setDob(object.getString("dob"));
actorClassVeriable.setCountry(object.getString("country"));
actorClassVeriable.setHeight(object.getString("height"));
actorClassVeriable.setSpouse(object.getString("spouse"));
actorClassVeriable.setChildren(object.getString("children"));
actorClassVeriable.setImage(object.getString("image"));
actorsList.add(actorClassVeriable);
}
return true;
}
//------------------>>
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
return false;
}
protected void onPostExecute(Boolean result) {
if(result == false)
Toast.makeText(getApplicationContext(), "Unable to fetch data from server", Toast.LENGTH_LONG).show();
}
}
- it scribes out the > HttpGet, HttpClient ,HttpResponse and HttpEntity