作为致命异常得到错误:AsyncTask#1进程java.lang.RuntimeException:执行doInBackground()时发生错误

时间:2019-03-01 06:04:24

标签: android

在获取错误的解决方法时,我上传了完整的错误,正如你们要求的那样,请尽快为我提供解决方案FATAL EXCEPTION: AsyncTask

java.lang.RuntimeException: An error occurred while executing doInBackground()java.lang.RuntimeException: An error occurred while executing doInBackground()
    at android.os.AsyncTask$3.done(AsyncTask.java:354)
    at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
    at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
    at java.util.concurrent.FutureTask.run(FutureTask.java:271)
    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
    at java.lang.Thread.run(Thread.java:764)
 Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/commons/logging/LogFactory;
    at org.apache.http.impl.client.AbstractHttpClient.<init>(AbstractHttpClient.java:182)
    at org.apache.http.impl.client.DefaultHttpClient.<init>(DefaultHttpClient.java:150)
    at com.example.fedov1.MainActivity$uploadToServer.doInBackground(MainActivity.java:133)
    at com.example.fedov1.MainActivity$uploadToServer.doInBackground(MainActivity.java:116)
    at android.os.AsyncTask$2.call(AsyncTask.java:333)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
    at java.lang.Thread.run(Thread.java:764) 
 Caused by: java.lang.ClassNotFoundException: Didn't find class "org.apache.commons.logging.LogFactory" on path: DexPathList[[zip file "/data/app/com.example.fedov1-ss7Jjv6bMfocdCHyFGUmHw==/base.apk", zip file "/data/app/com.example.fedov1-ss7Jjv6bMfocdCHyFGUmHw==/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.fedov1-ss7Jjv6bMfocdCHyFGUmHw==/split_lib_resources_apk.apk", zip file "/data/app/com.example.fedov1-ss7Jjv6bMfocdCHyFGUmHw==/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.fedov1-ss7Jjv6bMfocdCHyFGUmHw==/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.fedov1-ss7Jjv6bMfocdCHyFGUmHw==/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.fedov1-ss7Jjv6bMfocdCHyFGUmHw==/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.fedov1-ss7Jjv6bMfocdCHyFGUmHw==/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.fedov1-ss7Jjv6bMfocdCHyFGUmHw==/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.fedov1-ss7Jjv6bMfocdCHyFGUmHw==/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.fedov1-ss7Jjv6bMfocdCHyFGUmHw==/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.fedov1-ss7Jjv6bMfocdCHyFGUmHw==/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.fedov1-ss7Jjv6bMfocdCHyFGUmHw==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.fedov1-ss7Jjv6bMfocdCHyFGUmHw==/lib/arm64, /system/lib64]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
    at org.apache.http.impl.client.AbstractHttpClient.<init>(AbstractHttpClient.java:182) 
    at org.apache.http.impl.client.DefaultHttpClient.<init>(DefaultHttpClient.java:150) 
    at com.example.fedov1.MainActivity$uploadToServer.doInBackground(MainActivity.java:133) 
    at com.example.fedov1.MainActivity$uploadToServer.doInBackground(MainActivity.java:116) 
    at android.os.AsyncTask$2.call(AsyncTask.java:333) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
    at java.lang.Thread.run(Thread.java:764) 
    Suppressed: java.io.IOException: No original dex files found for dex location /data/app/com.example.fedov1-ss7Jjv6bMfocdCHyFGUmHw==/split_lib_resources_apk.apk
    at dalvik.system.DexFile.openDexFileNative(Native Method)
    at dalvik.system.DexFile.openDexFile(DexFile.java:354)
    at dalvik.system.DexFile.<init>(DexFile.java:101)
    at dalvik.system.DexFile.<init>(DexFile.java:75)
    at dalvik.system.DexPathList.loadDexFile(DexPathList.java:394)
    at dalvik.system.DexPathList.makeDexElements(DexPathList.java:354)
    at dalvik.system.DexPathList.<init>(DexPathList.java:164)
    at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:74)
    at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:65)
    at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:64)
    at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:73)
    at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:88)
    at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:74)
    at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:40)
    at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:727)
    at android.app.LoadedApk.getClassLoader(LoadedApk.java:810)
    at android.app.LoadedApk.getResources(LoadedApk.java:1032)
    at android.app.ContextImpl.createAppContext(ContextImpl.java:2357)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5792)
    at android.app.ActivityThread.access$1100(ActivityThread.java:202)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1665)
    at android.os.Handler.dispatchMessage(Handler.java:107)
    at android.os.Looper.loop(Looper.java:198)
    at android.app.ActivityThread.main(ActivityThread.java:6729)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

我添加此行的原因是

StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
StrictMode.setVmPolicy(builder.build()); 

或其他一些问题可以指导我

protected String doInBackground(Void... params) {

            ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
            nameValuePairs.add(new BasicNameValuePair("base64", ba1));
            nameValuePairs.add(new BasicNameValuePair("ImageName", System.currentTimeMillis() + ".jpg"));
            try {
                HttpClient httpclient = new DefaultHttpClient();
                HttpPost httppost = new HttpPost(URL);
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                HttpResponse response = httpclient.execute(httppost);
                String st = EntityUtils.toString(response.getEntity());
                Log.v("log_tag", "In the try Loop" + st);

            } catch (Exception e) {
                Log.v("log_tag", "Error in http connection " + e.toString());
            }
            return "Success";

        }

1 个答案:

答案 0 :(得分:0)

尝试像这样在AndroidManifest.xml中添加这些行

<uses-library android:name ="org.apache.http.legacy"
 android:required ="false"/>