xebia-functional/appsly-android-rest

Caché error on Android 2.3.3

Angelmmiguel opened this issue · 1 comments

I have a problem with a Samsung Ace 2 (Android 2.3.3). I see that the cache is disabled, but it causes a NullPointerException. The logcat is:

02-04 15:41:43.170 22719-22719/org.arpil.arpil E/android-rest﹕ main -> Cache will be disabled
java.lang.NullPointerException
at ly.apps.android.rest.utils.ObjectCache.getDiskCacheDir(ObjectCache.java:73)
at ly.apps.android.rest.utils.ObjectCache.(ObjectCache.java:41)
at ly.apps.android.rest.cache.ContextPersistentCacheManager.(ContextPersistentCacheManager.java:42)
at ly.apps.android.rest.client.RestClientFactory.defaultClient(RestClientFactory.java:43)
at org.arpil.arpil.RememberActivity.getPildora(RememberActivity.java:311)
at org.arpil.arpil.RememberActivity.onStart(RememberActivity.java:139)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1132)
at android.app.Activity.performStart(Activity.java:3817)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1624)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3691)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:670)
at dalvik.system.NativeStart.main(Native Method)
....
....
....

02-04 15:41:43.260 22719-22719/org.arpil.arpil E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: com.jakewharton.DiskLruCache
at com.integralblue.httpresponsecache.compat.libcore.net.http.HttpResponseCache.(HttpResponseCache.java:83)
at com.integralblue.httpresponsecache.HttpResponseCache.(HttpResponseCache.java:155)
at com.integralblue.httpresponsecache.HttpResponseCache.install(HttpResponseCache.java:192)
at ly.apps.android.rest.cache.CacheAwareHttpClient.enableHttpResponseCache(CacheAwareHttpClient.java:65)
at ly.apps.android.rest.client.RestClientFactory$1.(RestClientFactory.java:45)
at ly.apps.android.rest.client.RestClientFactory.defaultClient(RestClientFactory.java:43)
at org.arpil.arpil.RememberActivity.getPildora(RememberActivity.java:311)
at org.arpil.arpil.RememberActivity.onStart(RememberActivity.java:139)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1132)
at android.app.Activity.performStart(Activity.java:3817)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1624)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3691)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:670)
at dalvik.system.NativeStart.main(Native Method)

There is the errors :).

Thanks for the work!

@Angelmmiguel You may customize the client initialization and even provide your own implementations for most of the internals. In your case there may be devices where some third party lib in this case DiskLruCache fails to initialize certain cache location. For this case you can do something like these...

RestClient client = new DefaultRestClientImpl(
    new CacheAwareHttpClient(new ContextPersistentCacheManager(context)) {{
        //enableHttpResponseCache(10 * 1024 * 1024, new File(context.getCacheDir(), "android-rest-http"));
    }},
    new JacksonQueryParamsConverter(),
    new DelegatingConverterService(){{
        addConverter(new JacksonBodyConverter());
        addConverter(new JacksonHttpFormValuesConverter());
    }}
);

Or simply provide a different location where you know the device has access to write. We try to setup sensible defaults but it may not fit absolutely all cases and devices.