Android Studio 在 DefaultHttpClient 中出现错误

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)


浮云间
浏览 241回答 2
2回答

holdtom

在 build.gradle 文件中转到 android 块并使用 apache 库。前任。android{&nbsp;useLibrary&nbsp;'org.apache.http.legacy'}

qq_遁去的一_1

在AndroidManifest.xml里面<application>部分,添加:<uses-library&nbsp;android:name="org.apache.http.legacy"&nbsp;android:required="false"/>(在我的情况下,在 gradle 中添加 useLibrary 不起作用。)
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java