您好我正在尝试从数据库中获取一些数据,并且在更新助手之后我的应用程序意外崩溃。这是日志。
FATAL EXCEPTION: AsyncTask #1
AndroidRuntime Process: com.androbaron.materialnews, PID: 16246
AndroidRuntime java.lang.RuntimeException: An error occurred while executing doInBackground()
AndroidRuntime at android.os.AsyncTask$3.done(AsyncTask.java:309)
AndroidRuntime at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
AndroidRuntime at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
AndroidRuntime at java.util.concurrent.FutureTask.run(FutureTask.java:242)
AndroidRuntime at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
AndroidRuntime at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
AndroidRuntime at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
AndroidRuntime at java.lang.Thread.run(Thread.java:818)
AndroidRuntime Caused by: java.lang.NoSuchMethodError: No virtual method execute(Lorg/apache/http/client/methods/HttpUriRequest;)Lorg/apache/http/client/methods/CloseableHttpResponse; in class Lorg/apache/http/impl/client/DefaultHttpClient; or its super classes (declaration of 'org.apache.http.impl.client.DefaultHttpClient' appears in /system/framework/org.apache.http.legacy.boot.jar)
AndroidRuntime at com.androbaron.materialnews.json.JSONStream.getJsonResult(JSONStream.java:54)
AndroidRuntime at com.androbaron.materialnews.data.RecipeLoader.doInBackground(RecipeLoader.java:33)
AndroidRuntime at com.androbaron.materialnews.data.RecipeLoader.doInBackground(RecipeLoader.java)
AndroidRuntime at android.os.AsyncTask$2.call(AsyncTask.java:295)
AndroidRuntime at java.util.concurrent.FutureTask.run(FutureTask.java:237)
AndroidRuntime ... 4 more
RecipeLoader.java
@Override
protected List<Recipe> doInBackground(String... params) {
try {
Thread.sleep(100);
List<NameValuePair> param = new ArrayList<>();
JsonReader reader = jsonStream.getJsonResult(URL, JSONStream.METHOD_GET, param);
return getRecipeArray(reader);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
JSONStream.java
public JsonReader getJsonResult(String url, String method,List<NameValuePair> params) {
// Making HTTP request
try {
// check for request method
if(method == METHOD_POST){
// request method is POST / defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new UrlEncodedFormEntity(params));
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
}else if(method == METHOD_GET){
// request method is GET
DefaultHttpClient httpClient = new DefaultHttpClient();
String paramString = URLEncodedUtils.format(params, "utf-8");
url += "?" + paramString;
HttpGet httpGet = new HttpGet(url);
//Log.d("url", url);
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
InputStreamReader inputStreamReader = new InputStreamReader(is, "UTF-8");
//Log.e("ERRRR", "E : " + inputStreamReader.toString());
jsonReader = new JsonReader(inputStreamReader);
return jsonReader;
} catch (Exception e) {
Log.e("Buffer Error", "Error converting result " + e.toString());
return null;
}
}
有人解决这个问题吗? 我是android开发的新手。
答案 0 :(得分:0)
尝试将其添加到app build.gradle
中defaultConfig {
applicationId "com.example.example1"
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName "1.0"
multiDexEnabled true
useLibrary "org.apache.http.legacy"
}