解析失败:lorg/apache/http/util/args-创建时-新建bytearraybody(imagebytes,“image/jpeg”);

vptzau2j  于 2021-07-13  发布在  Java
关注(0)|答案(0)|浏览(109)

我一直试图用我的android应用程序将一个图像传输到servlet服务器端,我得到了这个错误

Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/util/Args;

我使用的是我在谷歌上找到的一个代码,这是我得到的。
ide-android工作室
android侧码
型号\u servlet.java:

public Boolean uploadBook(Book newBook) throws IOException {
    // TODO Auto-generated method stub
    Bitmap bookPic = newBook.getBookPic();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bookPic.compress(Bitmap.CompressFormat.PNG, 100, baos);
    byte[] imageBytes = baos.toByteArray();

    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost(url + "/BookUploadServlet");

    String boundary = "-------------" + System.currentTimeMillis();

    httpPost.setHeader("Content-type", "multipart/form-data; boundary=" + boundary);

    ByteArrayBody bookImage = new ByteArrayBody(imageBytes, "image/jpeg");
    StringBody sbOwner = new StringBody(newBook.getBookName(), ContentType.TEXT_PLAIN);

    HttpEntity entity = MultipartEntityBuilder.create()
            .setMode(HttpMultipartMode.BROWSER_COMPATIBLE)
            .setBoundary(boundary)
            .addPart("bookname", sbOwner)
            .addPart("bookpic", bookImage)
            .build();

    httpPost.setEntity(entity);

    HttpResponse response = httpclient.execute(httpPost);
    HttpEntity resEntity = response.getEntity();

    System.out.println(response.getStatusLine());
    if (resEntity != null) {
        System.out.println(EntityUtils.toString(resEntity));
    }
    if (resEntity != null) {
        resEntity.consumeContent();
    }

    httpclient.getConnectionManager().shutdown();

    return false;
}

java servlet代码:bookuploadservlet.java:

public class BookUploadServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
 * @see HttpServlet#HttpServlet()
 */
public BookUploadServlet() {
    super();
    // TODO Auto-generated constructor stub
}

/**
 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
 */
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    { 
          Collection<Part> parts = request.getParts();
          if (parts.size() != 3) {
             //can write error page saying all details are not entered 
           } 

           Part filePart = request.getPart("bookpic");
           InputStream imageInputStream = filePart.getInputStream();

           //read imageInputStream 
           filePart.write("somefiepath");
           //can also write the photo to local storage 

           //Read Name, String Type  
           Part namePart = request.getPart("bookname");
           if(namePart.getSize() > 20){
               //write name cannot exceed 20 chars 
           } 
           //use nameInputStream if required         
           InputStream nameInputStream = namePart.getInputStream();
           //name , String type can also obtained using Request parameter  
           String nameParameter = request.getParameter("bookname");
           System.out.println(nameParameter);

           //Similialrly can read age properties 
           Part agePart = request.getPart("age");
           int ageParameter = Integer.parseInt(request.getParameter("age"));

        }
}

/**
 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
 */
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    doGet(request, response);
}

}

完整错误日志:
com.example.liran.tbookandroid e/androidruntime:致命异常:asynctask#4进程:com.example.liran.tbookandroid,pid:28111 java.lang.runtimeexception:在android.os.asynctask$3.done(asynctask)上执行doinbackground()时出错。java:300)在java.util.concurrent.futuretask.finishcompletion(futuretask。java:355)在java.util.concurrent.futuretask.setexception(futuretask。java:222)在java.util.concurrent.futuretask.run(futuretask。java:242)在android.os.asynctask$serialexecutor$1.run(异步任务。java:231)位于java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor。java:1112)在java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor。java:587)在java.lang.thread.run(线程。java:818)原因:java.lang.noclassdeffounderror:解析失败:lorg/apache/http/util/args;在org.apache.http.entity.mime.content.abstractcontentbody。java:48)在org.apache.http.entity.mime.content.bytearraybody。java:74)在org.apache.http.entity.mime.content.bytearraybody。java:67)在org.apache.http.entity.mime.content.bytearraybody。java:87)在com.example.liran.tbookandroid.amodel.servlet\ model.model\ servlet.uploadbook(model\ servlet。java:159)在com.example.liran.tbookandroid.uploadbookpage.uploadbookfragment$uploadnewbook.doinbackground(uploadbookfragment。java:160)在com.example.liran.tbookandroid.uploadbookpage.uploadbookfragment$uploadnewbook.doinbackground(uploadbookfragment)。java:148)在android.os.asynctask$2.call(asynctask。java:288)在java.util.concurrent.futuretask.run(futuretask。java:237)在android.os.asynctask$serialexecutor$1.run(asynctask。java:231)  位于java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor。java:1112)  在java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor。java:587)  在java.lang.thread.run(线程。java:818)  原因:java.lang.classnotfoundexception:在路径:dexpathlist[[dex file”/data/data/com.example.liran.tbookandroid/files/instant run/dex/slice-slice\u 9\u 1f22eaf94d6a43c1ed432080a5b4c5afe2850a57-classes.dex上找不到类“org.apache.http.util.args”,dex file“/data/data/com.example.liran.tbookandroid/files/instant run/dex/slice-slice\u 8\u ab0226f587aa519424470ed5fcf18d3a05fde22f-classes.dex”,dex file“/data/data/com.example.liran.tbookandroid/files/instant run/dex/slice-slice\u 7\u 24ad75e4f6545fb5014b20c8d60b41818234b063-classes.dex”,dex file“/data/data/com.example.liran.tbookandroid/files/instant run/dex/slice-slice\u 6\u f630f64998260b15c9a69a940a52078c80cc85a3-classes.dex”,dex file“/data/com.example.liran.tbookandroid/files/instant run/dex/slice-slice\u 5\u a93ca339627382ab74e183b50d68cf45bfc4b916-classes.dex”,dex file“/data/data/com.example.liran.tbookandroid/files/instant run/dex/slice-slice\u 4\u 7f8feb0cee3e2f31f6d27354b6279c862b2f8ab3-classes.dex”,dex file“/data/com.example.liran.tbookandroid/files/instant run/dex/slice-slice\u 3\u 9102e6ca9566d990f4b8640b615b08a6b9c4fc93-classes.dex”,dex file“/data/data/com.example.liran.tbookandroid/files/instant run/dex/slice-slice\u 2\u 9d47b22d0a188feb20bfc04b87009f4f4fb122a1cc-classes.dex”,dex file“/data/com.example.liran.tbookandroid/files/instant run/dex/slice-slice\u 1\u 7560ea8962702ed20df197e3082ea640c944a69-classes.dex”,dex file“/data/data/com.example.liran.tbookandroid/files/instant run/dex/slice-slice\u 0\u c101d1c9924f3549a1fad0ddc31ef7aa5ac3108c-classes.dex”,dex file“/data/com.example.liran.tbookandroid/files/instant run/dex/slice-dependencies\u 636869a87c34641d26110ccf059f37768a7fdf1-classes.dex”],nativelibrarydirectories=[/vendor/lib,/system/lib,/供应商/lib,/system/lib]]位于dalvik.system.basedexclassloader.findclass(basedexclassloader。java:56)在com.android.tools.fd.runtime.incrementalclassloader$delegateclassloader.findclass(incrementalclassloader。java:90)在java.lang.classloader.loadclass(classloader。java:511)在java.lang.classloader.loadclass(classloader。java:469)在org.apache.http.entity.mime.content.abstractcontentbody.(抽象内容体)。java:48)  在org.apache.http.entity.mime.content.bytearraybody。java:74)  在org.apache.http.entity.mime.content.bytearraybody。java:67)  在org.apache.http.entity.mime.content.bytearraybody。java:87)  在com.example.liran.tbookandroid.amodel.servlet\u model.model\u servlet.uploadbook(model\u servlet)上。java:159)  在com.example.liran.tbookandroid.uploadbookpage.uploadbookfragment$uploadnewbook.doinbackground(uploadbookfragment。java:160)  在com.example.liran.tbookandroid.uploadbookpage.uploadbookfragment$uploadnewbook.doinbackground(uploadbookfragment。java:148)  在android.os.asynctask$2.call(asynctask。java:288)  在java.util.concurrent.futuretask.run(futuretask。java:237)  在android.os.asynctask$serialexecutor$1.run(asynctask。java:231)  位于java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor。java:1112)  在java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor。java:587)  在java.lang.thread.run(线程。java:818)  抑制:java.lang.classnotfoundexception:在dalvik.system.basedexclassloader.findclass(basedexclassloader)的路径:dexpathlist[[zip file”/data/app/com.example.liran.tbookandroid-2/base.apk“],nativelibrarydirectories=[/vendor/lib,/system/lib]]上找不到类“org.apache.http.util.args”。java:56)在java.lang.classloader.loadclass(clas
库列表:

httpclient-4.2.3.jar
httpcore-4.2.3.jar
httpmime-4.3.jar
json-simple-1.1.1.jar

如果你们认为上传pic有更好的代码或者servlet端有更好的代码,请帮助我并告诉我。这是我第一次处理这种事情(服务器端),所以我非常感谢任何帮助。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题