In global definition I have declared: private HashMap<String, Bitmap> map = new HashMap<String, Bitmap>();
In other part of my code, I connect to server and get my required info. Two of then are image address (url) and image id. after that I download image and I want to assign it its own Id. This is my code:
private LinkedList<Bitmap> getFlagImages() {
InputStream is= null;
LinkedList<Bitmap> llBitmap = new LinkedList<Bitmap>();
for(int i = 0; i < flag.getTeamLogo44x44().size(); i++) {
String urlstr = flag.getTeamLogo44x44().get(i);
try {
HttpGet httpRequest = new HttpGet(urlstr);
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = (HttpResponse) httpclient.execute(httpRequest);
HttpEntity entity = response.getEntity();
BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(entity);
is = bufHttpEntity.getContent();
Bitmap bm = BitmapFactory.decodeStream(is);
llBitmap.add(bm);
map.put(flag.getTeamId().get(i), bm); // *Crash happens here
}catch ( MalformedURLException e ){
Log.d( "RemoteImageHandler", "Invalid URL passed" + urlstr );
}catch ( IOException e ){
Log.d( "RemoteImageHandler", "fetchImage IO exception: " + e );
}finally{
if(is != null) {
try{
is.close();
} catch(IOException e) {}
}
}
}
return llBitmap;
}
When I run, the application crashes and logcat shows Null Pointer Exception and points to line map.put(flag.getTeamId().get(i), bm);
Any suggestion would be appreciated.
// Update,
Also I used map.put(flag.getTeamId().get(i), Bitmap.createBitmap(bm));
but the result was same.