Skip to content Skip to sidebar Skip to footer

Nullpointerexception At Imagecatche

I doesn't know what exactly the error in ImagaeCatche.params.It shows the null pointer exception.I indicate the error number at the end of the line. StackTrace: E/AndroidRuntime(

Solution 1:

Did you maybe forget to include:

<uses-permissionandroid:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

Edit: It seems that your getExternalCacheDir(context) returns null. Take a look at: http://developer.android.com/reference/android/content/Context.html#getExternalCacheDir%28%29. It says that it returns null "if external storage is not currently mounted so it could not ensure the path exists". You should check if it is null before calling getPath() with it and call instead context.getCacheDir().getPath().

Solution 2:

The value of AppConstants.IMAGE_CACHE_DIR and its reference is in the function:

publicstatic 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 dirfinalStringcachePath=
        Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) ||
                !isExternalStorageRemovable() ?    getExternalCacheDir(context).getPath() : <---402nd Error 
                        context.getCacheDir().getPath();

returnnewFile(cachePath + File.separator + uniqueName);
}  

That varies when using it for emulator, phone. i.e. the accessing of path on the sdCard.

So you need(ed) to check the scenario under what device were you getting that error.

Solution 3:

SD card wasn't properly access in android->sdk->tools.I find these problem in Console.

Then creating a new Avd and accessing the new SD Card.I can solve my problem.

Solution 4:

I would take a look at this one here. I don't deal with Fragments all that frequently, but after backpedaling through your nice error line comments (we thank you for that) I would have to assume that the context is not ready at the point you call getActivity(). So, this would probably need to be called at a different moment in the life-cycle. And this is one problem of a couple that someone started that they had been following up.

NullPointer on getActivity() from Fragment

Perhaps if this does not solve your problem, then a follow-up solution might. Good luck.

Post a Comment for "Nullpointerexception At Imagecatche"