ftb*_*ftb 20 android picasso okhttp
我在我的项目中使用Picasso库来加载图像和缓存它们.它没有任何问题,效果很好.但是,当我尝试使用OkHttp库与我的服务器(JSON通信)进行数据通信时,Picasso会抛出异常.
我使用以下罐子:okhttp-2.0.0-RC2,okio-1.0.0,picasso-2.2.0.当我添加这些罐子后运行我的项目时,它崩溃了以下内容:
06-12 11:13:15.824: E/dalvikvm(12105): Could not find class 'com.squareup.okhttp.HttpResponseCache', referenced from method com.squareup.picasso.OkHttpDownloader.<init>
Run Code Online (Sandbox Code Playgroud)
我添加了okhttp只是为了使用以下方法:
public static String executeHttpGet(String urlStr) {
Response response = null;
String result = "";
OkHttpClient client = new OkHttpClient();
try {
Request request = new Request.Builder().url(urlStr).build();
response = client.newCall(request).execute();
result = response.body().string();
} catch (Exception ex) {
}
return result;
}
Run Code Online (Sandbox Code Playgroud)
上面的代码没有任何问题.然而,使用Picasso库并且用于完美工作的代码开始抛出以下例外:
06-12 11:19:49.307: E/AndroidRuntime(13036): FATAL EXCEPTION: main
06-12 11:19:49.307: E/AndroidRuntime(13036): java.lang.NoClassDefFoundError: com.squareup.okhttp.HttpResponseCache
06-12 11:19:49.307: E/AndroidRuntime(13036): at com.squareup.picasso.OkHttpDownloader.<init>(OkHttpDownloader.java:74)
06-12 11:19:49.307: E/AndroidRuntime(13036): at com.squareup.picasso.OkHttpDownloader.<init>(OkHttpDownloader.java:51)
06-12 11:19:49.307: E/AndroidRuntime(13036): at com.squareup.picasso.OkHttpDownloader.<init>(OkHttpDownloader.java:41)
06-12 11:19:49.307: E/AndroidRuntime(13036): at com.squareup.picasso.Utils$OkHttpLoaderCreator.create(Utils.java:319)
06-12 11:19:49.307: E/AndroidRuntime(13036): at com.squareup.picasso.Utils.createDefaultDownloader(Utils.java:171)
06-12 11:19:49.307: E/AndroidRuntime(13036): at com.squareup.picasso.Picasso$Builder.build(Picasso.java:490)
06-12 11:19:49.307: E/AndroidRuntime(13036): at com.squareup.picasso.Picasso.with(Picasso.java:390)
Run Code Online (Sandbox Code Playgroud)
我的课程路径:
如果我删除okhttp-2.0.0-RC2,okio-1.0.0,Picasso线路工作.
为什么会这样?我如何一起使用两个库?
mar*_*osh 22
这个组合对我有用:
compile 'com.squareup.okhttp:okhttp:2.2.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.2.0'
compile 'com.squareup.picasso:picasso:2.4.0'
Run Code Online (Sandbox Code Playgroud)
Jes*_*son 19
切换到毕加索2.3.2.你还需要okhttp-urlconnection-2.0.0-RC2.
//Below code for Picasso initializing once for the app
private Picasso picasso;
private OkHttpClient okHttpClient;
okHttpClient = new OkHttpClient();
picasso = new Picasso.Builder(this)
.downloader(new OkHttpDownloader(okHttpClient))
.build();
//Below code to retrieve the images whereever required on the app
picasso.with(context).load(imageUrl).placeholder(R.drawable.ic_launcher)
Run Code Online (Sandbox Code Playgroud)
上面的代码对我来说很好.
归档时间: |
|
查看次数: |
18313 次 |
最近记录: |