I found this snippet on the internet:
try{
URL url = new URL(imgUrl+imageId[position]+".png");
HttpURLConnection con = (HttpURLConnection)url.openConnection();
InputStream is = con.getInputStream();
Bitmap bmp = BitmapFactory.decodeStream(is);
imageView.setImageBitmap(bmp);
}catch(Exception e) {
System.out.println(e.getMessage());
}
The code doesn't give me any errors,I am getting the exact url I want. But the ImageView stays empty. Running the debugger I got no problem upto: InputStream is = con.getInputStream();
After this the debugger goes to the catch block, and debugger window shows
NetworkOnMainThreadException
I know it's because I am doing network operations on the UI thread , but my activity already is extending another class, so I can't extend AsycnTask. Any workaround for this?
Plus: If there is an exception, shouldn't the app crash? My app runs fine, but the imageview doesn't show anything.