(2017最新博彩导航) android使用okhttp总是报错,代码在java工程中运行没有问题

报错如下:

代码如下:

public class httpRequest {
OkHttpClient client = new OkHttpClient; String runString url throws IOException { Request request = new Request.Builder.urlurl.build; Response response = client.newCallrequest.execute; if response.isSuccessful { return response.body.string; } else { throw new IOException"Unexpected code " + response; }
}

}

@Override
protected void onCreateBundle savedInstanceState { super.onCreatesavedInstanceState; setContentViewR.layout.activity_main; tv = TextView findViewByIdR.id.tt; httpRequest request = new httpRequest; try { String response = request.run"https://www.baidu.com"; tv.setTextresponse; System.out.printlnresponse; Log.d"res", response; } catch IOException e { // TODO Auto-generated catch block Log.d"error", "error!!!!!"; e.printStackTrace; }
} 用okhttp3也是这样,提示找不到okhttp.okHttpClient

android项目里面有没有导入okHttp的包啊?报错信息指明了OkHttpClient这个类没有找到啊

你是导入jar包还是直接compile里添加的?

使用okhttp的时候还要添加另外一个包的依赖

compile com.squareup.okio:okio:1.5.0

1、DexPathList中的dex中未包含okhttpclient,说明你打包的时候,没有把okhttp的依赖包打进apk中
2、建议从eclipse转到android studio

发表评论

电子邮件地址不会被公开。 必填项已用*标注