OkHTTP和毕加索不跑起来 [英] OkHTTP and Picasso don't run together

查看:231
本文介绍了OkHTTP和毕加索不跑起来的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用毕加索库在我的项目中加载图像,安德缓存。它的工作原理很好,没有任何问题。然而,当我尝试使用OkHttp库来执行我的服务器(JSON通信)的数据通信,毕加索抛出异常。

I use Picasso library in my project to load images ande cache them. It works good without any problem. However, when I try to use OkHttp library to perform data communication with my server (JSON communication), Picasso throws exceptions.

我用下面的罐子:okhttp-2.0.0-RC2,奥基奥-1.0.0,毕加索-2.2.0。当我运行我的项目后,我添加这些罐子,它崩溃并出现以下内容:

I use the following jars : okhttp-2.0.0-RC2, okio-1.0.0, picasso-2.2.0. When I run my project after I add these jars, It crashes with the following :

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>

我添加okhttp只是为了使用下面的方法:

I added okhttp just to use the following method :

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;
}

以上code工作没有任何问题。然而,codeS它们使用毕加索库,并用来很好地工作,开始引发以下excecption:

The above code works without any problem. However the codes which use Picasso library and used to work perfectly, start to throw the following excecption :

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)

我的类路径:

My Class Path :

如果我删除okhttp-2.0.0-RC2,奥基奥-1.0.0,毕加索线工作。

If I remove okhttp-2.0.0-RC2, okio-1.0.0, Picasso lines work.

这是为什么发生?如何使用两个库一起?

Why is that happening ? How can I use two libraries together ?

推荐答案

切换到毕加索2.3.2。您还需要okhttp-的URLConnection-2.0.0-RC2。

Switch to Picasso 2.3.2. You'll also need okhttp-urlconnection-2.0.0-RC2.

这篇关于OkHTTP和毕加索不跑起来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆