0

ListView に画像を設定しようとしていて、アダプター コードを作成しましたが、正常に動作しているように見えますが、実際に画像を取得するための行で、画像が見つからないというエラーが常に発生します。

画像を取得するコードは次のとおりです。

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);

次に ListView に適用されるコードは次のとおりです。

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);

エラーは

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:
4

1 に答える 1

1

ここで確認できますandroid.widget.SimpleAdapter SimpleAdapter のsetViewImageメソッドは 2 つのパラメーターのみを受け入れます。

最初のパラメータ: 現在の画像を設定する ImageView id

2 番目のパラメータ: 文字列 (ファイル パスから ImageView src を設定する場合) または Integer (ドローアブルの ID から ImageView src を設定する場合)

したがって、ドローアブルのビットマップではなく、ドローアブルIDのみを渡す必要があります

于 2013-06-06T22:07:42.860 に答える