0

I'm trying to set a Image on the ListView and I've written the adapter code and it seems to work fine, but the line of the to actually get the image is always giving an error about not being able to find an image.

The code to get the image is as follows,

Bitmap logo = BitmapFactory.decodeResource(MainActivity.this.getResources(), R.drawable.dm);

// creating new HashMap
HashMap<String, Object> map = new HashMap<String, Object>();

// adding each child node to HashMap key => value
map.put(TAG_BODY, id);
map.put(TAG_TITLE, name);
map.put(TAG_URL, uri);
map.put(TAG_TIME, dateFormated);
map.put(TAG_SITE, logo);

// adding HashList to ArrayList
productsList.add(map);

The code that then applies to ListView is

ListAdapter adapter;
adapter = new SimpleAdapter(
MainActivity.this, productsList,
R.layout.list_row, new String[] { TAG_BODY, TAG_TITLE, TAG_URL, TAG_TIME, TAG_SITE},
  new int[] { R.id.id, R.id.headline, R.id.url, R.id.time, R.id.list_i});

// updating listview
setListAdapter(adapter);

and the error is

06-06 22:39:44.283  32407-32407/com.mystraldesign.aggregate    E/BitmapFactory: Unable to decode stream: java.io.FileNotFoundException: /: open failed: EISDIR (Is a directory)
06-06 22:39:44.283  32407-32407/com.mystraldesign.aggregate    I/System.out: resolveUri failed on bad bitmap uri:
06-06 22:39:44.283  32407-32407/com.mystraldesign.aggregate    E/BitmapFactory: Unable to decode stream: java.io.FileNotFoundException: /: open failed: EISDIR (Is a directory)
06-06 22:39:44.283  32407-32407/com.mystraldesign.aggregate    I/System.out: resolveUri failed on bad bitmap uri:
06-06 22:39:44.293  32407-32411/com.mystraldesign.aggregate    D/dalvikvm: GC_CONCURRENT freed 276K, 22% free 10335K/13112K, paused 2ms+3ms, total 22ms
06-06 22:39:44.293  32407-32407/com.mystraldesign.aggregate    E/BitmapFactory: Unable to decode stream: java.io.FileNotFoundException: /: open failed: EISDIR (Is a directory)
06-06 22:39:44.293  32407-32407/com.mystraldesign.aggregate    I/System.out: resolveUri failed on bad bitmap uri:
06-06 22:39:44.303  32407-32407/com.mystraldesign.aggregate    E/BitmapFactory: Unable to decode stream: java.io.FileNotFoundException: /: open failed: EISDIR (Is a directory)
06-06 22:39:44.303  32407-32407/com.mystraldesign.aggregate    I/System.out: resolveUri failed on bad bitmap uri:
06-06 22:39:44.303  32407-32407/com.mystraldesign.aggregate    E/BitmapFactory: Unable to decode stream: java.io.FileNotFoundException: /: open failed: EISDIR (Is a directory)
06-06 22:39:44.303  32407-32407/com.mystraldesign.aggregate    I/System.out: resolveUri failed on bad bitmap uri:
06-06 22:39:44.313  32407-32407/com.mystraldesign.aggregate    E/BitmapFactory: Unable to decode stream: java.io.FileNotFoundException: /: open failed: EISDIR (Is a directory)
06-06 22:39:44.313  32407-32407/com.mystraldesign.aggregate    I/System.out: resolveUri failed on bad bitmap uri:
06-06 22:39:44.313  32407-32407/com.mystraldesign.aggregate    E/BitmapFactory: Unable to decode stream: java.io.FileNotFoundException: /: open failed: EISDIR (Is a directory)
06-06 22:39:44.313  32407-32407/com.mystraldesign.aggregate    I/System.out: resolveUri failed on bad bitmap uri:
06-06 22:39:44.313  32407-32407/com.mystraldesign.aggregate    E/BitmapFactory: Unable to decode stream: java.io.FileNotFoundException: /: open failed: EISDIR (Is a directory)
06-06 22:39:44.313  32407-32407/com.mystraldesign.aggregate    I/System.out: resolveUri failed on bad bitmap uri:
06-06 22:39:44.323  32407-32407/com.mystraldesign.aggregate    E/BitmapFactory: Unable to decode stream: java.io.FileNotFoundException: /: open failed: EISDIR (Is a directory)
06-06 22:39:44.323  32407-32407/com.mystraldesign.aggregate    I/System.out: resolveUri failed on bad bitmap uri:
06-06 22:39:44.333  32407-32407/com.mystraldesign.aggregate    E/BitmapFactory: Unable to decode stream: java.io.FileNotFoundException: /: open failed: EISDIR (Is a directory)
06-06 22:39:44.333  32407-32407/com.mystraldesign.aggregate    I/System.out: resolveUri failed on bad bitmap uri:

1 Answer 1

1

you can see here android.widget.SimpleAdapter SimpleAdapter's setViewImage method accept only two parameters :

First Param : ImageView id in which you want to set current image

Second Param : String (if you want to set ImageView src from file path) or Integer( if you want to set ImageView src from drawable's id)

so you will need to pass only drawable id instead of Bitmap of drawable

Sign up to request clarification or add additional context in comments.

3 Comments

Ok, but how do you actually go about doing that. e.g. the SimpleAdapter call
@JamesKraw : because you are storing Object in HashMap instead of String or Integer
Yeah figured it out thanks. Was as simply as changing the map.put(TAG_SITE, logo); to map.put(TAG_SITE, R.drawable.logo); and removing all the BitMap stuff. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.