Maison > Questions et réponses > le corps du texte
报错如下:
代码如下:
public class httpRequest {
OkHttpClient client = new OkHttpClient();
String run(String url) throws IOException {
Request request = new Request.Builder().url(url).build();
Response response = client.newCall(request).execute();
if (response.isSuccessful()) {
return response.body().string();
} else {
throw new IOException("Unexpected code " + response);
}
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv = (TextView) findViewById(R.id.tt);
httpRequest request = new httpRequest();
try {
String response = request.run("https://www.baidu.com");
tv.setText(response);
System.out.println(response);
Log.d("res", response);
} catch (IOException e) {
// TODO Auto-generated catch block
Log.d("error", "error!!!!!");
e.printStackTrace();
}
}
用okhttp3也是这样,提示找不到okhttp.okHttpClient
伊谢尔伦2017-04-17 17:31:45
1、DexPathList中的dex中未包含okhttpclient,说明你打包的时候,没有把okhttp的依赖包打进apk中
2、建议从eclipse转到android studio