简体   繁体   中英

Android: Unable to find class inside my project

Hi guys recently I noticed that sometimes my app crashes when calling/trying to initiate a class I created with the following error:

Fatal Exception: java.lang.NoClassDefFoundError com.myapp.classes.ImageSdCardCache

I am trying to reference/call ImageSdCardCache in an activity like this:

 ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
    .denyCacheImageMultipleSizesInMemory()
    .memoryCache(new WeakMemoryCache())
    .diskCache(new ImageSdCardCache(new File(Environment.getExternalStorageDirectory().getPath() + "/MyAppCache/cache"))) //the problem line
    .defaultDisplayImageOptions(options)
    .memoryCacheExtraOptions(300,300)
    .build();

Here I am trying to initiate an ImageLoader but sometimes (not always) it fails with no class found exception. What am I doing wrong?

Here is ImageSdCardCache.java placed in a folder different from the folder my activity is in.

public class ImageSdCardCache extends BaseDiskCache {

public ImageSdCardCache(File cacheDir) {
    super(cacheDir);
}
}

Don't sure if this is the cause, but consider what mention in docs:

getExternalStorageDirectory() Return the primary external storage directory. This directory may not currently be accessible if it has been mounted by the user on their computer, has been removed from the device, or some other problem has happened. You can determine its current state with getExternalStorageState().

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM