Điều tôi đang cố làm là gửi ảnh đến máy chủ web. Khi tôi gọi một phương thức trong dự án Android của mình, tôi nhận được lỗi sau: không thể tìm thấy lớp 'org.apache.http.entity.mime.content.Filebody', được tham chiếu từ phương thức com.example.tc.Send.send.Không thể tìm thấy lớp 'org.apache.http.entity.mime.content.Filebody', được tham chiếu từ phương thức
Điều này xảy ra dù cho tôi đã có hàng nhập khẩu như sau:
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.impl.client.DefaultHttpClient;
Đây là những gì trông giống như lớp trong đó phương pháp này nằm:
public class Send {
public Send(){
}
public static String send(String path) throws Exception {
String filePath = path;
String svar;
HttpClient httpclient = new DefaultHttpClient();
try {
HttpPost httppost = new HttpPost("path to web server");
FileBody pic = new FileBody(new File(filePath));
MultipartEntity requestEntity = new MultipartEntity();
requestEntity.addPart("file", pic);
httppost.setEntity(requestEntity);
System.out.println("executing request " + httppost.getRequestLine());
HttpResponse response = httpclient.execute(httppost);
HttpEntity responseEntity = response.getEntity();
System.out.println("----------------------------------------");
System.out.println(response.getStatusLine());
ByteArrayOutputStream outstream = new ByteArrayOutputStream();
response.getEntity().writeTo(outstream);
byte [] responseBody = outstream.toByteArray();
svar = new String(responseBody);
System.out.println(svar);
} finally {
try {
httpclient.getConnectionManager().shutdown();
}
catch (Exception ignore) {
}
}
return svar;
}
}
bất cứ ai có thể thấy vấn đề là gì?
Bạn có chắc chắn bao gồm nó trong đường dẫn java xây dựng? –
bạn đã tìm thấy câu trả lời chưa? –
Bạn đang sử dụng proguard? –