简体   繁体   English

Android:无法在我的项目中找到课程

[英]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: 我正在尝试在这样的活动中引用/调用ImageSdCardCache:

 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. 在这里,我尝试启动ImageLoader,但有时(并非总是)它失败,没有找到类异常。 What am I doing wrong? 我究竟做错了什么?

Here is ImageSdCardCache.java placed in a folder different from the folder my activity is in. 这是ImageSdCardCache.java放在与我的活动所在的文件夹不同的文件夹中。

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. getExternalStorageDirectory()返回主外部存储目录。 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(). 您可以使用getExternalStorageState()确定其当前状态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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