gpt4 book ai didi

java.lang.NoClassDefFoundError 与 HttpResponseCache 和 DiskLruCache

转载 作者:太空狗 更新时间:2023-10-29 12:43:49 25 4
gpt4 key购买 nike

我正在尝试在一个新的 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)

我从项目 HttpResponseCache by Craig Andrews 复制了两个 jar 和 DiskLruCache 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();
}
}

我在其他线程中读到这是顺序问题,因此在 Java 构建路径的“订购和导出”选项卡中,我将其放在首位: Build Path
Order and Export

我清理了项目,重建了但没有任何效果,问题仍然存在...
任何的想法...??

谢谢。

最佳答案

因为你使用了disklrucache-2.0.2.jarhttpresponsecache-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 你应该使用版本 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

关于java.lang.NoClassDefFoundError 与 HttpResponseCache 和 DiskLruCache,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21329326/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com