/ / l'image ne se charge pas à l'aide de json à partir de l'URL - android, json

l'image ne se charge pas en utilisant json depuis l'url - android, json

Voici mon code. L'espace image reste vide. Pas en cours de chargement. Quelle est mon erreur ici?
de quel type de code ai-je encore besoin. donner plus de définition pls.

public class MainActivity extends AppCompatActivity {

private String TAG = MainActivity.class.getSimpleName();

private ProgressDialog progressDialog;
private ListView listView;

// JSON data url
private static String Jsonurl = "http://microblogging.wingnity.com/JSONParsingTutorial/jsonActors";
ArrayList<HashMap<String, String>> contactJsonList;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

contactJsonList = new ArrayList<>();
listView = (ListView) findViewById(R.id.listview);
new GetContacts().execute();
}

private class GetContacts extends AsyncTask<Void, Void, Void> {

@Override
protected void onPreExecute() {
super.onPreExecute();
// Showing progress dialog
progressDialog = new ProgressDialog(MainActivity.this);
progressDialog.setMessage("Please wait...");
progressDialog.setCancelable(false);
progressDialog.show();
}

@Override
protected Void doInBackground(Void... arg0) {
HTTPHandler httpHandler = new HTTPHandler();

// request to json data url and getting response
String jsonString = httpHandler.makeServiceCall(Jsonurl);
Log.e(TAG, "Response from url: " + jsonString);
if (jsonString != null) {
try {
JSONObject jsonObject = new JSONObject(jsonString);
// Getting JSON Array node
JSONArray contacts = jsonObject.getJSONArray("actors");

for (int i = 0; i < contacts.length(); i++) {

JSONObject c = contacts.getJSONObject(i);
String name = c.getString("name");
String country = c.getString("country");
String spouse = c.getString("spouse");
String dob = c.getString("dob");
String description = c.getString("description");
String children = c.getString("children");
String image = c.getString("image");

// tmp hash map for single contact
HashMap<String, String> contact = new HashMap<>();

// adding each child node to HashMap key => value
contact.put("name", name);
contact.put("country", country);
contact.put("spouse", spouse);
contact.put("dob", dob);
contact.put("description", description);
contact.put("children", children);
contact.put("image", image);

// adding contact to contact list
contactJsonList.add(contact);
}
} catch (final JSONException e) {
Log.e(TAG, "Json parsing error: " + e.getMessage());
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(), "Json parsing error: " + e.getMessage(),Toast.LENGTH_LONG).show();
}
});
}
} else {
Log.e(TAG, "Could not get json from server.");
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(),"Could not get json from server.",Toast.LENGTH_LONG).show();
}
});
}
return null;
}

@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
// Dismiss the progress dialog
if (progressDialog.isShowing())
progressDialog.dismiss();

/**     * Updating parsed JSON data into ListView    * */
ListAdapter adapter = new SimpleAdapter(MainActivity.this, contactJsonList, R.layout.row,
new String[]{"name","country", "spouse", "dob", "description", "children", "image"},
new int[]{R.id.name, R.id.country, R.id.spouse, R.id.dob, R.id.description, R.id.children, R.id.imageview});

listView.setAdapter(adapter);
}
}
}

Merci de votre aide

Réponses:

1 pour la réponse № 1

Si vous souhaitez charger une image à partir d'une URL Utilisez un adaptateur personnalisé et utilisez la bibliothèque Picasso ou Glide pour charger l'image. ou alors Si vous souhaitez utiliser simpleAdapter, vérifiez ce lien Image de l'URL dans ListView à l'aide de SimpleAdapter


0 pour la réponse № 2

vous pouvez utiliser la bibliothèque Glide pour charger l'image à partir de l'url, regardez le code ci-dessous, cela peut vous aider de manière simple

compilez cette bibliothèque

compile "com.github.bumptech.glide:glide:4.0.0-RC0"

que de charger une image comme celle-ci

Glide.with(HomeClass.this)
.load(userProfileUrl)
.centerCrop()
.diskCacheStrategy(DiskCacheStrategy.NONE)
.skipMemoryCache(true)
.dontAnimate()
.into(imageview);

0 pour la réponse № 3

Voulez-vous charger la liste des images à partir de l'URL? ensuite consultez le lien ci-dessous, il existe un exemple détaillé de travail avec une liste d'images en utilisant json avec la bibliothèque volly. Exemple

J'espère que cela t'aidera.