Hier ist mein Code. Der Bildbereich bleibt leer. Wird nicht geladen. Was ist mein Fehler hier?
welche Art von Code brauche ich wieder. geben mehr Definition pls.Bild lädt nicht mit Json von der URL
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);
}
}
}
Dank für Ihre Hilfe
Das Bild, das Sie gerade lesen, ich denke, es ist eine URL. Sie müssen also Ihre Bitmap von der Image-URL in Ihrem Adapter laden. Überprüfen Sie also Ihren Adaptercode. – Akash