我在Eclipse Neon 32位中使用此代码,没有错误(AsyncTask类例程):
protected String doInBackground(String... params) {
// do above Server call here
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("name",name));
try
{
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
//THE ERROR...
HttpResponse response = httpclient.execute(httppost);
...................................
但是在Eclipse Neon 64位和Android Studio(当然是64位)中,当我跟踪执行线程时,我发现此行中的错误:
HttpResponse response = httpclient.execute(httppost);
是否可能由于“ org.apache.http.HttpResponse”库而出现此错误?...也许是为32位开发应用程序编写的,已过时了...如果有人知道解决方案,请帮助我!
更新!我发现使用adb的“ logcat”错误...就是这样:
12-21 21:28:26.175 28178 28379 E AndroidRuntime: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
12-21 21:28:26.175 28178 28379 E AndroidRuntime: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
12-21 21:28:26.175 28178 28379 E AndroidRuntime: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
12-21 21:28:26.175 28178 28379 E AndroidRuntime: at java.lang.Thread.run(Thread.java:764)
12-21 21:28:26.175 28178 28379 E 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)
12-21 21:28:26.175 28178 28379 E AndroidRuntime: at com.example.woossapp.ui.home.HomeFragment$RutinaCreareJson.doInBackground(HomeFragment.java:281)
12-21 21:28:26.175 28178 28379 E AndroidRuntime: at com.example.woossapp.ui.home.HomeFragment$RutinaCreareJson.doInBackground(HomeFragment.java:246)
12-21 21:28:26.175 28178 28379 E AndroidRuntime: at android.os.AsyncTask$2.call(AsyncTask.java:333)
12-21 21:28:26.175 28178 28379 E AndroidRuntime: at java.util.concurrent.FutureTask.run(FutureTask.java:266)
12-21 21:28:26.175 28178 28379 E AndroidRuntime: ... 4 more
12-21 21:28:26.185 2304 11940 W ActivityManager: Force finishing activity com.example.woossapp/.MainActivity
12-21 21:28:26.190 2304 11940 W ContextImpl: Calling a method in the system process without a qualified user: android.app.ContextImpl.sendBroadcast:966 com.android.server.am.AppErrors.crashApplicationInner:393 com.android.server.am.AppErrors.crashApplication:321 com.android.server.am.ActivityManagerService.handleApplicationCrashInner:14517 com.android.server.am.ActivityManagerService.handleApplicationCrash:14499
12-21 21:28:26.196 2304 2364 I ActivityManager: Showing crash dialog for package com.example.woossapp u0
12-21 21:28:26.197 2304 2363 W BroadcastQueue: Background execution not allowed: receiving Intent { act=android.intent.action.DROPBOX_ENTRY_ADDED flg=0x10 (has extras) } to com.google.android.gms/.stats.service.DropBoxEntryAddedReceiver
12-21 21:28:26.197 2304 2363 W BroadcastQueue: Background execution not allowed: receiving Intent { act=android.intent.action.DROPBOX_ENTRY_ADDED flg=0x10 (has extras) } to com.google.android.gms/.chimera.GmsIntentOperationService$PersistentTrustedReceiver
我仍然不明白。也许库不兼容。如果有人拥有Http库和替换该代码的好方法,我将提前感谢他。
嗯,“错误”是“ DefaultHttpClient”类,它已过时the error