我正在尝试在一个新项目 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 文件夹中的 Craig Andrews 的项目 HttpResponseCache和Jake Wharton 的 DiskLruCache复制了两个 jar :
这是我的 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 & Export 选项卡中,我把它放在首位:
我清理了项目,重建并且没有任何工作,问题仍然存在......
任何想法......??
谢谢。