我从我的哈希图中收到一个空值。这是哈希图的创建:
private HashMap<String,Bitmap> thumbs = new HashMap<String,Bitmap>();
/* adding a single value to the hashmap */
然后我继续从哈希图中检索值,如下所示:
public Bitmap getImageByFileName(String fileName) {
Bitmap fish = null;
Iterator it = thumbs.entrySet().iterator();
while (it.hasNext()) {
Map.Entry pairs = (Map.Entry)it.next();
fish = (Bitmap)thumbs.get(fileName);
it.remove();
}
Log.i("shnitzel", " bitmap is " + fish);
fish = (Bitmap)thumbs.get(fileName);
Log.i("shnitzel", " final bitmap is " + fish);
return fish;
}
日志文件:
08-05 22:18:28.170: I/shnitzel(477): bitmap is android.graphics.Bitmap@40650138
08-05 22:18:28.170: I/shnitzel(477): final bitmap is null
正如你所看到的,我在'while'循环内部和外部使用完全相同的命令,但由于某种原因,它在内部工作,而不是在外部工作。为什么会这样?