Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/201.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 获取图像缓存时出现NullPointerException_Android_Caching_Nullpointerexception - Fatal编程技术网

Android 获取图像缓存时出现NullPointerException

Android 获取图像缓存时出现NullPointerException,android,caching,nullpointerexception,Android,Caching,Nullpointerexception,我正在使用来自的类,并且在某些设备上遇到了问题(我的应用程序不会在我测试过的所有设备上崩溃,而是在其他人上崩溃) 注意:发生这种情况的Android版本是:2.3.3-2.3.7、4.0.3-4.0.4、4.1和4.2 在我的Google开发者控制台中,我得到以下堆栈跟踪: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.question/com.question.ui.question}: java

我正在使用来自的类,并且在某些设备上遇到了问题(我的应用程序不会在我测试过的所有设备上崩溃,而是在其他人上崩溃)

注意:发生这种情况的Android版本是:2.3.3-2.3.7、4.0.3-4.0.4、4.1和4.2

在我的Google开发者控制台中,我得到以下堆栈跟踪:

java.lang.RuntimeException: Unable to start activity 
ComponentInfo{com.question/com.question.ui.question}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2077)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2104)
at android.app.ActivityThread.access$600(ActivityThread.java:134)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1247)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:4624)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.question.util.ImageCache.getDiskCacheDir(ImageCache.java:568)
at com.question.util.ImageCache$ImageCacheParams.<init>(ImageCache.java:488)
at com.question.ui.question.onCreate(question.java:58)
at android.app.Activity.performCreate(Activity.java:4479)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1050)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2041)
... 11 more

如果有人知道这是什么问题,并能解释,那将是有帮助的

我遇到了这个问题,发现我的AVD模拟器配置不正确。具体而言,空指针是由于缺少定义和分配给虚拟设备的存储空间

要解决此问题,请使用SD卡存储新建或编辑Android虚拟设备。在Eclipse中:选择Andoid虚拟设备管理器图标=>CreateNew=>。。。靠近页面底部的是一个名为SD卡的部分:输入SD卡大小的值

下面介绍如何使用适当的存储配置AVD仿真器


以下是生成NullPointerException的良好技术定义。

我也遇到了同样的问题。请查看这些
http://stackoverflow.com/questions/24121307/nullpointerexception-at-imagecatche/24156251#24156251
。这可能会对您有所帮助。
public static File getDiskCacheDir(Context context, String uniqueName) {
    // Check if media is mounted or storage is built-in, if so, try and use external cache dir
    // otherwise use internal cache dir
    final String cachePath =
            Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) ||
            !isExternalStorageRemovable() ? getExternalCacheDir(context).getPath() :
                            context.getCacheDir().getPath();

    return new File(cachePath + File.separator + uniqueName);
}