2019-03-05 11:29:55.278 9180-9180/com.example.test E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.test, PID: 9180
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.test.MainActivity.onCreate(MainActivity.java:49)
at android.app.Activity.performCreate(Activity.java:7136)
at android.app.Activity.performCreate(Activity.java:7127)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
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)
Caused by: java.lang.ClassNotFoundException: Didnt find class "org.apache.commons.logging.LogFactory" on path: DexPathList[[zip file "/data/app/com.example.test-BbzvMenf4XBEEfyOW7lpKw==/base.apk", zip file "/data/app/com.example.test-BbzvMenf4XBEEfyOW7lpKw==/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.test-BbzvMenf4XBEEfyOW7lpKw==/split_lib_resources_apk.apk", zip file "/data/app/com.example.test-BbzvMenf4XBEEfyOW7lpKw==/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.test-BbzvMenf4XBEEfyOW7lpKw==/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.test-BbzvMenf4XBEEfyOW7lpKw==/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.test-BbzvMenf4XBEEfyOW7lpKw==/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.test-BbzvMenf4XBEEfyOW7lpKw==/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.test-BbzvMenf4XBEEfyOW7lpKw==/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.test-BbzvMenf4XBEEfyOW7lpKw==/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.test-BbzvMenf4XBEEfyOW7lpKw==/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.test-BbzvMenf4XBEEfyOW7lpKw==/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.test-BbzvMenf4XBEEfyOW7lpKw==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.test-BbzvMenf4XBEEfyOW7lpKw==/lib/x86, /system/lib]]
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.test.MainActivity.onCreate(MainActivity.java:49)
at android.app.Activity.performCreate(Activity.java:7136)
at android.app.Activity.performCreate(Activity.java:7127)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
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)
Suppressed: java.io.IOException: No original dex files found for dex location /data/app/com.example.test-BbzvMenf4XBEEfyOW7lpKw==/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)
答案 0 :(得分:1)
在build.gradle文件中,转到android块并使用apache库。例如
android{ useLibrary 'org.apache.http.legacy'}
答案 1 :(得分:1)
在 AndroidManifest.xml
部分内的 <application>
中,添加:
<uses-library android:name="org.apache.http.legacy" android:required="false"/>
(在 gradle 中添加 useLibrary 在我的情况下不起作用。)