views:

146

answers:

2

I've been trying to use the CacheManager for caching some http requests but it failed every time with a nullpointer exception. After some digging I believe I found out why:

CacheManager.getCacheFileBaseDir() always returns null so when I try to use CacheManager.getCacheFile() or CacheManager.saveCacheFile() they fail.

CacheManager.cacheDisabled() returns false.

I hadn 't created a cache partition via the AVD manager so I thought the problem lie there. But after creating a cache partition getCacheFile() still return null:

03-16 00:25:16.321: ERROR/AndroidRuntime(296): Caused by: java.lang.NullPointerException
03-16 00:25:16.321: ERROR/AndroidRuntime(296): at android.webkit.CacheManager.getCacheFile(CacheManager.java:296)

What could be the problem? I've got the code posted here: http://pastebin.com/eaJwfXEK But it's a bit messy because I've been trying tons of stuff.

Why does CacheManager.getCacheFileBaseDir() return null and not a File object?

A: 

it seems there is a init(Context context) method to call but by viewing the source code, this method is not public I can't call this method from my code.

I have always: java.lang.NullPointerException at android.webkit.CacheManager.getCacheFile(CacheManager.java:295)

Paris freelance
+1  A: 

Could be related to http://code.google.com/p/android/issues/detail?id=7222 : The CacheManager can only be used associated to a WebView. Bummer. I'll continue investigating.

digitarald