I am trying to get image in ImageView from url website but the image not show so, What is the wrong in this code? This is the url of the image.
It is my Main Activi
Doing network IO in the main thread is evil. Better to avoid.
Also - your url resource access is wrong.
Use something like this instead:
private Bitmap bmp;
new AsyncTask() {
@Override
protected Void doInBackground(Void... params) {
try {
InputStream in = new URL(IMAGE_URL).openStream();
bmp = BitmapFactory.decodeStream(in);
} catch (Exception e) {
// log error
}
return null;
}
@Override
protected void onPostExecute(Void result) {
if (bmp != null)
imageView.setImageBitmap(bmp);
}
}.execute();
This is the 'old way' of loading url resources into display. Frankly speaking, I have not written such code in a long time. Volley and Picasso simply do it much better than me, including transparent local cache, multiple loader-threads management and enabling effective resize-before-load policies. All but coffee :)