当前位置: 首页 > 知识库问答 >
问题:

致命异常java.lang.noClassDefFoundError:解析失败:lorg/apache/http/util/args

贾骏
2023-03-14

我正在使用HttpPost方法向服务器发送录制的音频文件,但收到以下错误:

致命异常java.lang.noClassDefFoundError:解析失败:lorg/apache/http/util/args

下面是我的代码:

File is = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/" + "javacodegeeksRecording.3gpp");           

String yourNodeJsBluemixRoute = "http://mobilefeedbackform.mybluemix.net";
 try {
     Toast.makeText(MainActivity.this,
            "Inside try", Toast.LENGTH_LONG)
                .show();
        System.out.println(is);
        HttpClient client = new DefaultHttpClient();
        HttpPost post = new HttpPost(yourNodeJsBluemixRoute);
        Toast.makeText(MainActivity.this,
                "Before sending", Toast.LENGTH_LONG)
                   .show();
        post.setHeader("enctype", "multipart/form-data");

        /*FileBody bin = new FileBody(is);*/
        FileBody fb = new FileBody(is, "audio/3gpp");
        MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
        reqEntity.addPart("file", fb); /*I believe that the "file" is the name in php part*/
        post.setEntity(reqEntity);

        HttpResponse response = client.execute(post);

        Toast.makeText(MainActivity.this,
                "Now sending", Toast.LENGTH_LONG)
                   .show();
        HttpEntity resEntity = response.getEntity();
        if (resEntity != null) {
            String responseBody = EntityUtils.toString(resEntity);
            String resp = responseBody;
            Toast.makeText(MainActivity.this,
                    resp, Toast.LENGTH_LONG)
                       .show();
            Log.i("RESPONSE", EntityUtils.toString(resEntity));
        }
            } catch (Exception e) {
    e.printStackTrace();
        }

       } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
   }
08-19 19:57:17.517: E/AndroidRuntime(1377): FATAL EXCEPTION: main
08-19 19:57:17.517: E/AndroidRuntime(1377): Process: com.example.android_test, PID: 1377
08-19 19:57:17.517: E/AndroidRuntime(1377): java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/util/Args;
08-19 19:57:17.517: E/AndroidRuntime(1377):     at org.apache.http.entity.mime.content.AbstractContentBody.<init>(AbstractContentBody.java:48)
08-19 19:57:17.517: E/AndroidRuntime(1377):     at org.apache.http.entity.mime.content.FileBody.<init>(FileBody.java:96)
08-19 19:57:17.517: E/AndroidRuntime(1377):     at org.apache.http.entity.mime.content.FileBody.<init>(FileBody.java:85)
08-19 19:57:17.517: E/AndroidRuntime(1377):     at com.example.android_test.MainActivity.play(MainActivity.java:181)
08-19 19:57:17.517: E/AndroidRuntime(1377):     at com.example.android_test.MainActivity$3.onClick(MainActivity.java:91)
08-19 19:57:17.517: E/AndroidRuntime(1377):     at android.view.View.performClick(View.java:4756)
08-19 19:57:17.517: E/AndroidRuntime(1377):     at android.view.View$PerformClick.run(View.java:19749)
08-19 19:57:17.517: E/AndroidRuntime(1377):     at android.os.Handler.handleCallback(Handler.java:739)
08-19 19:57:17.517: E/AndroidRuntime(1377):     at android.os.Handler.dispatchMessage(Handler.java:95)
08-19 19:57:17.517: E/AndroidRuntime(1377):     at android.os.Looper.loop(Looper.java:135)
08-19 19:57:17.517: E/AndroidRuntime(1377):     at android.app.ActivityThread.main(ActivityThread.java:5221)
08-19 19:57:17.517: E/AndroidRuntime(1377):     at java.lang.reflect.Method.invoke(Native Method)
08-19 19:57:17.517: E/AndroidRuntime(1377):     at java.lang.reflect.Method.invoke(Method.java:372)
08-19 19:57:17.517: E/AndroidRuntime(1377):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
08-19 19:57:17.517: E/AndroidRuntime(1377):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
08-19 19:57:17.517: E/AndroidRuntime(1377): Caused by: java.lang.ClassNotFoundException: Didn't find class "org.apache.http.util.Args" on path: DexPathList[[zip file "/data/app/com.example.android_test-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
08-19 19:57:17.517: E/AndroidRuntime(1377):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
08-19 19:57:17.517: E/AndroidRuntime(1377):     at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
08-19 19:57:17.517: E/AndroidRuntime(1377):     at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
08-19 19:57:17.517: E/AndroidRuntime(1377):     ... 15 more
08-19 19:57:17.517: E/AndroidRuntime(1377):     Suppressed: java.lang.ClassNotFoundException: org.apache.http.util.Args
08-19 19:57:17.517: E/AndroidRuntime(1377):         at java.lang.Class.classForName(Native Method)
08-19 19:57:17.517: E/AndroidRuntime(1377):         at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
08-19 19:57:17.517: E/AndroidRuntime(1377):         at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
08-19 19:57:17.517: E/AndroidRuntime(1377):         at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
08-19 19:57:17.517: E/AndroidRuntime(1377):         ... 16 more
08-19 19:57:17.517: E/AndroidRuntime(1377):     Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available

共有1个答案

空慈
2023-03-14

只需从-http://www.java2s.com/code/jar/h/downloadhttpcore43beta1jar.htm]1下载最新的http jar

并将其添加到项目的libs文件夹中。

不要忘记在build.gradle中添加编译文件('libs/httpcore-4.3-beta1.jar')依赖项

 类似资料: