I have a Adapter in my application which inflates posts and shows them in a ListView
. Each post has an image, so it uses LruCache
to store images.
The app works well completely, but it crashed two or three times and I couldn't realize what was the problem. Only last time, I could get this log from LogCat:
E/AndroidRuntime(2407): Caused by: java.lang.NullPointerException: key == null || value == null
The crashes happen only when app is recently installed (When I delete the app from the device and install it again)! When I open the app for the first time and start scrolling up and down so fast, sometimes it crashes. (It won't happen all the time, it's completely random!)
And after that, it won't crash anymore... :/
I think it has something to do with LruCache and empty cache. I saw this question, but that wasn't my problem! I did check for null cache in my code:
if (MainActivity.thumbnailsCache.get(postID) != null)
{
imageViewThumbnail.setImageBitmap(MainActivity.thumbnailsCache.get(postID));
} else {
new DownloadAndSetImageTask(thumbnailURL).execute();
}
Any suggestion?
P.S.: I know my question doesn't have enough details, but that's all the information I have!