致命异常java.lang.NoClassDefFoundError:解析失败:Lorg / apache / http / util / Args

时间:2015-08-19 14:40:48

标签: java android http

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

  

FATAL EXCEPTION 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();
        }
   }

我缺少什么?

logcat错误:

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

2 个答案:

答案 0 :(得分:2)

只需从 - http://www.java2s.com/Code/Jar/h/Downloadhttpcore43beta1jar.htm] 1

下载最新的http jar

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

不要忘记在compile files('libs/httpcore-4.3-beta1.jar')

中添加build.gradle依赖项

这对我有用。快乐的编码:)

答案 1 :(得分:0)

我还在研究apache的东西,我遇到了这个错误。 我可以通过下载.jar来修复它,然后手动将它链接到项目设置中。

您应该在app / build / libs下移动jar 文件&gt;&gt;项目结构&gt;&gt;依赖性&gt;&gt; +&gt;&gt;文件依赖性&gt;&gt;然后将其更改为提供而不是编译(如果导入的jar太多,则编译将导致非零值为1的java退出)