我有这个内部类,通过发布已保存在设备内部存储上的图像来调用Web服务:
public class OCRScan extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground (String... params) {
String result = "";
try{
String picturePath = params[0];
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("http://172.16.1.7:8080/OCRService/webresources/read");
MultipartEntityBuilder multipartEntity = MultipartEntityBuilder.create();
multipartEntity.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
multipartEntity.addPart("image/jpeg", new FileBody(new File (picturePath)));
post.setEntity(multipartEntity.build());
final HttpResponse response = client.execute(post);
StringWriter writer = new StringWriter();
IOUtils.copy(response.getEntity().getContent(), writer);
result= writer.toString();
} catch (Exception ex) {
System.out.println("FAILED TO CALL SERVICE: ");
System.out.println(ex.getMessage());
}
return result;
}
@Override
protected void onPostExecute (String result) {
//setResultOnUi(result);
System.out.println("RESULT RETURNED FROM YOUR SERVICE: \n" + result);
}
}
我在父类中执行此异步任务,如下所示:
OCRScan scan = new OCRScan();
scan.execute(picturePath);
之后我得到了这个&#34;机器人barf&#34;在log cat中:
06-03 12:10:43.316: D/libEGL(15788): loaded /system/lib/egl/libEGL_mali.so
06-03 12:10:43.321: D/libEGL(15788): loaded /system/lib/egl/libGLESv1_CM_mali.so
06-03 12:10:43.326: D/libEGL(15788): loaded /system/lib/egl/libGLESv2_mali.so
06-03 12:10:43.331: E/(15788): Device driver API match
06-03 12:10:43.331: E/(15788): Device driver API version: 23
06-03 12:10:43.331: E/(15788): User space API version: 23
06-03 12:10:43.331: E/(15788): mali: REVISION=Linux-r3p2-01rel3 BUILD_DATE=Fri Nov 29 14:18:37 KST 2013
06-03 12:10:43.401: D/OpenGLRenderer(15788): Enabling debug mode 0
06-03 12:10:45.591: W/IInputConnectionWrapper(15788): showStatusIcon on inactive InputConnection
06-03 12:11:03.411: W/dalvikvm(15788): VFY: unable to resolve static field 3891 (DEFAULT_BINARY) in Lorg/apache/http/entity/ContentType;
06-03 12:11:03.411: D/dalvikvm(15788): VFY: replacing opcode 0x62 at 0x0000
06-03 12:11:03.411: W/dalvikvm(15788): VFY: unable to find class referenced in signature (Lorg/apache/http/entity/ContentType;)
06-03 12:11:03.416: W/dalvikvm(15788): VFY: unable to find class referenced in signature (Lorg/apache/http/entity/ContentType;)
06-03 12:11:03.416: W/dalvikvm(15788): VFY: unable to resolve static field 3891 (DEFAULT_BINARY) in Lorg/apache/http/entity/ContentType;
06-03 12:11:03.416: D/dalvikvm(15788): VFY: replacing opcode 0x62 at 0x0000
06-03 12:11:03.416: W/dalvikvm(15788): VFY: unable to find class referenced in signature (Lorg/apache/http/entity/ContentType;)
06-03 12:11:03.416: W/dalvikvm(15788): VFY: unable to find class referenced in signature (Lorg/apache/http/entity/ContentType;)
06-03 12:11:03.416: W/dalvikvm(15788): VFY: unable to resolve static field 3891 (DEFAULT_BINARY) in Lorg/apache/http/entity/ContentType;
06-03 12:11:03.416: D/dalvikvm(15788): VFY: replacing opcode 0x62 at 0x0000
06-03 12:11:03.416: W/dalvikvm(15788): VFY: unable to find class referenced in signature (Lorg/apache/http/entity/ContentType;)
06-03 12:11:03.416: W/dalvikvm(15788): VFY: unable to find class referenced in signature (Lorg/apache/http/entity/ContentType;)
06-03 12:11:03.416: I/dalvikvm(15788): Could not find method org.apache.http.util.Args.notNull, referenced from method org.apache.http.entity.mime.MultipartEntityBuilder.addPart
06-03 12:11:03.416: W/dalvikvm(15788): VFY: unable to resolve static method 10394: Lorg/apache/http/util/Args;.notNull (Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object;
06-03 12:11:03.416: D/dalvikvm(15788): VFY: replacing opcode 0x71 at 0x0002
06-03 12:11:03.416: W/dalvikvm(15788): VFY: unable to resolve static field 3892 (DEFAULT_TEXT) in Lorg/apache/http/entity/ContentType;
06-03 12:11:03.416: D/dalvikvm(15788): VFY: replacing opcode 0x62 at 0x0000
06-03 12:11:03.416: W/dalvikvm(15788): VFY: unable to find class referenced in signature (Lorg/apache/http/entity/ContentType;)
06-03 12:11:03.416: W/dalvikvm(15788): VFY: unable to find class referenced in signature (Lorg/apache/http/entity/ContentType;)
06-03 12:11:03.421: W/dalvikvm(15788): VFY: unable to resolve static field 3891 (DEFAULT_BINARY) in Lorg/apache/http/entity/ContentType;
06-03 12:11:03.421: D/dalvikvm(15788): VFY: replacing opcode 0x62 at 0x0000
06-03 12:11:03.421: I/dalvikvm(15788): Could not find method org.apache.http.entity.ContentType.create, referenced from method org.apache.http.entity.mime.content.FileBody.<init>
06-03 12:11:03.421: W/dalvikvm(15788): VFY: unable to resolve static method 10200: Lorg/apache/http/entity/ContentType;.create (Ljava/lang/String;)Lorg/apache/http/entity/ContentType;
06-03 12:11:03.421: D/dalvikvm(15788): VFY: replacing opcode 0x71 at 0x0000
06-03 12:11:03.421: I/dalvikvm(15788): Could not find method org.apache.http.entity.ContentType.create, referenced from method org.apache.http.entity.mime.content.FileBody.<init>
06-03 12:11:03.421: W/dalvikvm(15788): VFY: unable to resolve static method 10201: Lorg/apache/http/entity/ContentType;.create (Ljava/lang/String;Ljava/lang/String;)Lorg/apache/http/entity/ContentType;
06-03 12:11:03.421: D/dalvikvm(15788): VFY: replacing opcode 0x71 at 0x0000
06-03 12:11:03.421: W/dalvikvm(15788): VFY: unable to find class referenced in signature (Lorg/apache/http/entity/ContentType;)
06-03 12:11:03.421: W/dalvikvm(15788): VFY: unable to find class referenced in signature (Lorg/apache/http/entity/ContentType;)
06-03 12:11:03.421: W/dalvikvm(15788): VFY: unable to find class referenced in signature (Lorg/apache/http/entity/ContentType;)
06-03 12:11:03.426: W/dalvikvm(15788): VFY: unable to find class referenced in signature (Lorg/apache/http/entity/ContentType;)
06-03 12:11:03.426: I/dalvikvm(15788): Could not find method org.apache.http.util.Args.notNull, referenced from method org.apache.http.entity.mime.content.FileBody.<init>
06-03 12:11:03.426: W/dalvikvm(15788): VFY: unable to resolve static method 10394: Lorg/apache/http/util/Args;.notNull (Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object;
06-03 12:11:03.426: D/dalvikvm(15788): VFY: replacing opcode 0x71 at 0x0005
06-03 12:11:03.426: I/dalvikvm(15788): Could not find method org.apache.http.util.Args.notNull, referenced from method org.apache.http.entity.mime.content.FileBody.writeTo
06-03 12:11:03.426: W/dalvikvm(15788): VFY: unable to resolve static method 10394: Lorg/apache/http/util/Args;.notNull (Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object;
06-03 12:11:03.426: D/dalvikvm(15788): VFY: replacing opcode 0x71 at 0x0002
06-03 12:11:03.426: I/dalvikvm(15788): Could not find method org.apache.http.entity.ContentType.parse, referenced from method org.apache.http.entity.mime.content.AbstractContentBody.<init>
06-03 12:11:03.426: W/dalvikvm(15788): VFY: unable to resolve static method 10205: Lorg/apache/http/entity/ContentType;.parse (Ljava/lang/String;)Lorg/apache/http/entity/ContentType;
06-03 12:11:03.426: D/dalvikvm(15788): VFY: replacing opcode 0x71 at 0x0000
06-03 12:11:03.426: W/dalvikvm(15788): VFY: unable to find class referenced in signature (Lorg/apache/http/entity/ContentType;)
06-03 12:11:03.426: I/dalvikvm(15788): Could not find method org.apache.http.util.Args.notNull, referenced from method org.apache.http.entity.mime.content.AbstractContentBody.<init>
06-03 12:11:03.426: W/dalvikvm(15788): VFY: unable to resolve static method 10394: Lorg/apache/http/util/Args;.notNull (Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object;
06-03 12:11:03.426: D/dalvikvm(15788): VFY: replacing opcode 0x71 at 0x0005
06-03 12:11:03.426: I/dalvikvm(15788): Could not find method org.apache.http.entity.ContentType.getCharset, referenced from method org.apache.http.entity.mime.content.AbstractContentBody.getCharset
06-03 12:11:03.426: W/dalvikvm(15788): VFY: unable to resolve virtual method 10203: Lorg/apache/http/entity/ContentType;.getCharset ()Ljava/nio/charset/Charset;
06-03 12:11:03.426: D/dalvikvm(15788): VFY: replacing opcode 0x6e at 0x0002
06-03 12:11:03.431: W/dalvikvm(15788): VFY: unable to find class referenced in signature (Lorg/apache/http/entity/ContentType;)
06-03 12:11:03.431: I/dalvikvm(15788): Could not find method org.apache.http.entity.ContentType.getMimeType, referenced from method org.apache.http.entity.mime.content.AbstractContentBody.getMediaType
06-03 12:11:03.431: W/dalvikvm(15788): VFY: unable to resolve virtual method 10204: Lorg/apache/http/entity/ContentType;.getMimeType ()Ljava/lang/String;
06-03 12:11:03.431: D/dalvikvm(15788): VFY: replacing opcode 0x6e at 0x0002
06-03 12:11:03.431: I/dalvikvm(15788): Could not find method org.apache.http.entity.ContentType.getMimeType, referenced from method org.apache.http.entity.mime.content.AbstractContentBody.getMimeType
06-03 12:11:03.431: W/dalvikvm(15788): VFY: unable to resolve virtual method 10204: Lorg/apache/http/entity/ContentType;.getMimeType ()Ljava/lang/String;
06-03 12:11:03.431: D/dalvikvm(15788): VFY: replacing opcode 0x6e at 0x0002
06-03 12:11:03.431: I/dalvikvm(15788): Could not find method org.apache.http.entity.ContentType.getMimeType, referenced from method org.apache.http.entity.mime.content.AbstractContentBody.getSubType
06-03 12:11:03.431: W/dalvikvm(15788): VFY: unable to resolve virtual method 10204: Lorg/apache/http/entity/ContentType;.getMimeType ()Ljava/lang/String;
06-03 12:11:03.431: D/dalvikvm(15788): VFY: replacing opcode 0x6e at 0x0002
06-03 12:11:03.431: W/dalvikvm(15788): threadid=12: thread exiting with uncaught exception (group=0x41e1a700)
06-03 12:11:03.436: E/AndroidRuntime(15788): FATAL EXCEPTION: AsyncTask #1
06-03 12:11:03.436: E/AndroidRuntime(15788): java.lang.RuntimeException: An error occured while executing doInBackground()
06-03 12:11:03.436: E/AndroidRuntime(15788): at android.os.AsyncTask$3.done(AsyncTask.java:299)
06-03 12:11:03.436: E/AndroidRuntime(15788): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
06-03 12:11:03.436: E/AndroidRuntime(15788): at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
06-03 12:11:03.436: E/AndroidRuntime(15788): at java.util.concurrent.FutureTask.run(FutureTask.java:239)
06-03 12:11:03.436: E/AndroidRuntime(15788): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
06-03 12:11:03.436: E/AndroidRuntime(15788): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
06-03 12:11:03.436: E/AndroidRuntime(15788): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
06-03 12:11:03.436: E/AndroidRuntime(15788): at java.lang.Thread.run(Thread.java:841)
06-03 12:11:03.436: E/AndroidRuntime(15788): Caused by: java.lang.NoClassDefFoundError: org.apache.http.entity.ContentType
06-03 12:11:03.436: E/AndroidRuntime(15788): at org.apache.http.entity.mime.content.FileBody.<init>(FileBody.java:89)
06-03 12:11:03.436: E/AndroidRuntime(15788): at com.deangrobler.imageocr.MainActivity$OCRScan.doInBackground(MainActivity.java:174)
06-03 12:11:03.436: E/AndroidRuntime(15788): at com.deangrobler.imageocr.MainActivity$OCRScan.doInBackground(MainActivity.java:1)
06-03 12:11:03.436: E/AndroidRuntime(15788): at android.os.AsyncTask$2.call(AsyncTask.java:287)
06-03 12:11:03.436: E/AndroidRuntime(15788): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
06-03 12:11:03.436: E/AndroidRuntime(15788): ... 4 more
然后应用程序崩溃..对此的任何帮助将非常感激。先谢谢!
答案 0 :(得分:1)
请从http://hc.apache.org/downloads.cgi下载httpmime,httpcore和httpclient库,并将其放在project / libs文件夹中。