Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPE after unmount SD card #170

Closed
silentnuke-old opened this issue Feb 13, 2013 · 9 comments
Closed

NPE after unmount SD card #170

silentnuke-old opened this issue Feb 13, 2013 · 9 comments
Labels

Comments

@silentnuke-old
Copy link

Hi.
Thanks for such usefull library. I am using loader1.8.0, I found one problem in loading an image. If i enable cacheOnDisc and cacheInMemory, then set cache folder on sdcard and unmount sdcard, the image dosen't show.
It will be great, if cacheOnDisc failed but cacheInMemory is enabled, cache image to memory and show.

Start display image task [my_valid_url]
Load image from Internet [my_valid_url]
Cache image on disc [my_valid_url]
null
java.lang.NullPointerException
    at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.saveImageOnDisc(LoadAndDisplayImageTask.java:311)
    at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.tryLoadBitmap(LoadAndDisplayImageTask.java:232)
    at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.run(LoadAndDisplayImageTask.java:148)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:390)
    at java.util.concurrent.FutureTask.run(FutureTask.java:234)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
    at java.lang.Thread.run(Thread.java:856)
@nostra13
Copy link
Owner

Hi,
Did you unmount SD card while app in background?

@silentnuke-old
Copy link
Author

I try unmount sdcard:

  1. before application start, first log for this situation
  2. while app in background, in this case NPE doesn't occurs, but it also doesn't show image.

@silentnuke-old
Copy link
Author

How I can set cacheDir after call init method?
For example on first start sdcard doesn't available, but later it become available.

@nostra13
Copy link
Owner

No way for current version. Let me think about a solution...

@silentnuke-old
Copy link
Author

For example provide a callback which will call to try get path for cache when current path not available

nostra13 added a commit that referenced this issue Mar 9, 2013
Cache images on device's file system if SD card becomes unmounted
@silentnuke-old
Copy link
Author

Hi, thanks for changes.
But there are problems:

  1. if reserve dir removed and sdcard unavailable, images not displayed.

Log:

Start display image task [http://***/images/image/f/0/img_f005ea093abff6a7bfd0458ee9b4eb9f.jpg_231x143]
Load image from Internet [http://***/images/image/f/0/img_f005ea093abff6a7bfd0458ee9b4eb9f.jpg_231x143]
Cache image on disc [http://***/images/image/f/0/img_f005ea093abff6a7bfd0458ee9b4eb9f.jpg_231x143]
/data/data/***/cache/uil-images/1996200885: open failed: ENOENT (No such file or directory)
java.io.FileNotFoundException: /data/data/***/cache/uil-images/1996200885: open failed: ENOENT (No such file or directory)
    at libcore.io.IoBridge.open(IoBridge.java:416)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:88)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:73)
    at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.saveImageOnDisc(LoadAndDisplayImageTask.java:301)
    at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.tryLoadBitmap(LoadAndDisplayImageTask.java:237)
    at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.run(LoadAndDisplayImageTask.java:149)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
    at java.lang.Thread.run(Thread.java:856)
Caused by: libcore.io.ErrnoException: open failed: ENOENT (No such file or directory)
    at libcore.io.Posix.open(Native Method)
    at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
    at libcore.io.IoBridge.open(IoBridge.java:400)
    ... 8 more

For fix in method tryLoadBitmap() make changes

File cacheDir = imageFile.getParentFile();
if (cacheDir == null || (!cacheDir.exists() && !cacheDir.mkdirs())) {
    imageFile = configuration.reserveDiscCache.get(uri);
    cacheDir = imageFile.getParentFile();
    if (cacheDir != null && !cacheDir.exists()) {
                cacheDir.mkdirs()
        }
}
  1. Can you provide some listener which will call when cachedir null or unavailable?
  2. What occurs when sdcard unavailable and no free space on internal storge? Image will not display or it will cache in memory and display?

@nostra13
Copy link
Owner

  1. I'll look into it
  2. I don't want to add additional listener but let me think.
  3. Handle "Not enough disc space" for disc cache #178 Only 1 Mb of internal storage is used, so I expect there is always free space on the device. Otherwise you can catch fail (Handle "Not enough disc space" for disc cache #178) and reload image without caching on disc.

@nostra13 nostra13 reopened this Mar 19, 2013
@silentnuke-old
Copy link
Author

  1. ok.
  2. it will be very useful, because if we start application when external storage is not currently mounted cacheDir setting to null and if we mount sdcard it still write image on internal memory until we have restart the application with mounted sdcard.
  3. maybe there way to load and show image when disckache enabled and cachedir not available without disabling cache on disc?

@nostra13
Copy link
Owner

Fixed since 1.8.3. UIL always check if disc cache is exists and create it if necessary. If no disc cache is available or there is not enough free space then UIL will load images in memory and display them anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants