I'm pretty new to Android Development and spent all day looking into issues with my ListAdapter, but couldn't find any answers that helped me solve my problem.
I Have a JSON NewsString parsed from an URL and need to load the Thumbnail into the ListView. I tried to Load it via Imageloader (https://github.com/novoda/ImageLoader#directloader-utility) and then convert the Bitmap to a Drawable so I can use it in my ListView (Did that before).
I Have the permissions in the Manifest:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
And the JsonObject is parsed in an AsyncTask where I try to load the image from Url.
try {
String url = e.getString("imageThumb");
Bitmap bmp = new DirectLoader().download(url);
Drawable d = new BitmapDrawable(null,bmp);
Log.d("getBitmap", d.toString());
row.put("thumb", d);
}catch (Exception e5) {
Log.e("IMG", "Failed to load Thumbnail From URL: "+e5.toString());
Drawable d = MainActivity.hweb_icon;
row.put("thumb", d);
}
but I always get the Same Error Message:
I tried several tutorials and other stuff, but it never worked out for me. The URL is correct and does not need any encoding.
My previous approach looked like this :
try {
String url = e.getString("imageThumb");
InputStream in = new java.net.URL(url).openStream();
Bitmap bmp = BitmapFactory.decodeStream(in);
Drawable d = new BitmapDrawable(null,bmp);
row.put("thumb", d);
}catch (Exception e5) {
// handle it
Log.e("IMG", "Failed to load Thumbnail From URL : "+e5.toString());
}
Sorry if this question was already answered, but I found many solutions and tried them, but none of them helped me out.
Thx
pwittke
EDIT: I created a new Testproject and the code below worked fine, so I started to deactivate every part that uses drawables somehow and turned out, that the SimpleAdapter cant load images that way... It can only load images from the resurces and not from an url... thx for your script britzl, it works fine, now I need to find a way to change my adapter for the images...