带有HttpResponseCache和DiskLruCache的java.lang.NoClassDefFoundError

时间:2014-01-24 09:46:14

标签: java android noclassdeffounderror httpresponsecache

我正在尝试在新项目Android中测试此缓存库 当我运行项目时,我得到了这个Logcat:

01-24 03:45:31.109: E/AndroidRuntime(1983): FATAL EXCEPTION: main
01-24 03:45:31.109: E/AndroidRuntime(1983): Process: com.test_cache, PID: 1983
01-24 03:45:31.109: E/AndroidRuntime(1983): java.lang.NoClassDefFoundError: com.jakewharton.DiskLruCache
01-24 03:45:31.109: E/AndroidRuntime(1983):     at com.integralblue.httpresponsecache.compat.libcore.net.http.HttpResponseCache.<init>(HttpResponseCache.java:83)
01-24 03:45:31.109: E/AndroidRuntime(1983):     at com.integralblue.httpresponsecache.HttpResponseCache.<init>(HttpResponseCache.java:155)
01-24 03:45:31.109: E/AndroidRuntime(1983):     at com.integralblue.httpresponsecache.HttpResponseCache.install(HttpResponseCache.java:192)
01-24 03:45:31.109: E/AndroidRuntime(1983):     at com.test_cache.MainActivity.onCreate(MainActivity.java:21)
01-24 03:45:31.109: E/AndroidRuntime(1983):     at android.app.Activity.performCreate(Activity.java:5243)
01-24 03:45:31.109: E/AndroidRuntime(1983):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
01-24 03:45:31.109: E/AndroidRuntime(1983):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2140)
01-24 03:45:31.109: E/AndroidRuntime(1983):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2226)
01-24 03:45:31.109: E/AndroidRuntime(1983):     at android.app.ActivityThread.access$700(ActivityThread.java:135)
01-24 03:45:31.109: E/AndroidRuntime(1983):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1397)
01-24 03:45:31.109: E/AndroidRuntime(1983):     at android.os.Handler.dispatchMessage(Handler.java:102)
01-24 03:45:31.109: E/AndroidRuntime(1983):     at android.os.Looper.loop(Looper.java:137)
01-24 03:45:31.109: E/AndroidRuntime(1983):     at android.app.ActivityThread.main(ActivityThread.java:4998)
01-24 03:45:31.109: E/AndroidRuntime(1983):     at java.lang.reflect.Method.invokeNative(Native Method)
01-24 03:45:31.109: E/AndroidRuntime(1983):     at java.lang.reflect.Method.invoke(Method.java:515)
01-24 03:45:31.109: E/AndroidRuntime(1983):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
01-24 03:45:31.109: E/AndroidRuntime(1983):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
01-24 03:45:31.109: E/AndroidRuntime(1983):     at dalvik.system.NativeStart.main(Native Method)

我从我的libs文件夹中的项目HttpResponseCache by Craig AndrewsDiskLruCache by Jake Wharton中复制了两个罐子:
Project Files

这是我的MainActivity.java:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    final long httpCacheSize = 10 * 1024 * 1024; // 10 MiB
    final File httpCacheDir = new File(getCacheDir(), "http");

    try {
        com.integralblue.httpresponsecache.HttpResponseCache.install(httpCacheDir, httpCacheSize);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }        
}

我在其他主题中读到了订单的问题,所以在订单&amp;在Java Build Path中导出选项卡,我把它放在第一位: Build Path
Order and Export

我清理了这个项目,重建并没有任何工作,问题仍然存在...... 任何的想法...??

感谢。

1 个答案:

答案 0 :(得分:3)

因为您使用了 disklrucache-2.0.2.jar httpresponsecache-1.3.jar

在库 httpresponsecache-1.3.jar 中使用 disklrucache-1.2.1.jar

disklrucache-1.2.1.jar 中,软件包为: com.jakewharton ,但在版本2.0.2中,软件包更改为 com.jakewharton。 disklrucache

这是根本原因。

如果您想使用 disklrucache ,则应使用版本1.2.1

您可以从这里下载:http://www.mediafire.com/download/e2q4vz7kdlwxxr3/disklrucache-1.2.1.jar(。jar)

或源文件:https://www.mediafire.com/?933nqqe9j4227cc(。jar)

希望这可以帮到你。

enter image description here