如何删除“import org.apache.http.entity.mime.content.ByteArrayBody;”中的错误

时间:2012-05-22 15:41:50

标签: android

我尝试下载[httpmime-4.0.1.jar],但仍然存在错误并且--------------------------- ----

class ImageUploadTask扩展AsyncTask {         @override

    protected String doInBackground(Void... unsued) {

        try {

            HttpClient httpClient = new DefaultHttpClient();





HttpContext localContext = new BasicHttpContext();
            HttpPost httpPost = new HttpPost(getString(R.string.WebServiceURL) + "/cfc/iphonewebservice.cfc?method=uploadPhoto");
            MultipartEntity entity = new MultipartEntity(

         HttpMultipartMode.BROWSER_COMPATIBLE);





ByteArrayOutputStream bos = new ByteArrayOutputStream();
            bitmap.compress(CompressFormat.JPEG, 100, bos);
            byte[] data = bos.toByteArray();
            entity.addPart("photoId", new StringBody(getIntent()



.getStringExtra("photoId")));
            entity.addPart("returnformat", new StringBody("json"));
            entity.addPart("uploaded", new ByteArrayBody(data,"myImage.jpg"));



    entity.addPart("photoCaption", new StringBody(caption.getText().toString()));
            httpPost.setEntity(entity);
            HttpResponse response = httpClient.execute(httpPost,
   localContext);

2 个答案:

答案 0 :(得分:2)

在您的应用程序中添加一个libs文件夹,然后添加“httpmime-4.1.3.jar”,之后您需要将此目录显示给您的项目属性。

答案 1 :(得分:0)

您应该将此JAR添加到构建路径。如果您正在使用Eclipse,只需将其复制到项目文件夹即可。然后在Eclipse中右键单击它,BUILD PATH-> ADD TO BUILD PATH