I am trying to display an image in listview from url using JSON parsing. the image url displays correctly in log. when i am trying to download image and display in list getting NullPointerException in bmImage.setImageBitmap(result); i am using following code can anyone tell me the solution..
private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
ImageView bmImage;
public DownloadImageTask(ImageView bmImage) {
this.bmImage = bmImage;
}
protected Bitmap doInBackground(String... urls) {
Bitmap bt_img = null;
try {
FileInputStream in = new FileInputStream(urls[0]);
InputStream in = new java.net.URL(urls[0]).openStream();
bt_img = BitmapFactory.decodeStream(in);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return bt_img;
}
protected void onPostExecute(Bitmap result) {
try {
bmImage.setImageBitmap(result);
} catch (Exception e) {
e.printStackTrace();
}
}
}