-1
我試圖通過我的java代碼執行文件附件操作。但它在我的控制檯輸出中返回「java.lang.NoClassDefFoundError」。你能幫我解決這個問題嗎?在我的代碼中沒有任何問題。在Java中處理「java.lang.NoClassDefFoundError」
以下是我的代碼:
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
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.HttpMultipartMode;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.HTTP;
public static void main(String[] args) throws Exception {
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("http://watsonexp-stg.corp.adobe.com/watson/api/bug/addAttachmentAPI.jsp");
//to make a multipart POST request
MultipartEntity multipartEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE, null, Charset.forName(HTTP.UTF_8));
multipartEntity.addPart("appGUID", new StringBody("e2513b90-f327-4cc0-8c07-2d79a1b6eddd"));
multipartEntity.addPart("userId", new StringBody("karansha"));
multipartEntity.addPart("password", new StringBody("RGVsbCUxMDA="));
multipartEntity.addPart("bugId", new StringBody("3402114"));
multipartEntity.addPart("fileDescription", new StringBody("trying to attach a file"));
multipartEntity.addPart("external", new StringBody("false"));
multipartEntity.addPart("Filedata", new FileBody(new File("C:/Users/karansha/Desktop/test.jpg")));
httpPost.setEntity(multipartEntity);
HttpResponse res= httpClient.execute(httpPost);
//following lines will print out the respose from the server on attempting to upload a file.
HttpEntity httpEntity = res.getEntity();
BufferedReader br = new BufferedReader(new InputStreamReader(httpEntity.getContent()));
String line = "";
while ((line = br.readLine()) != null){
System.out.println(line);
}
}
}
發佈完整的堆棧跟蹤 – Apurv
您是否介意顯示您的'import'行 – arajek
@SonuKrishan上述代碼中的哪一行是拋出異常並不清楚。請像Apurv詢問那樣發佈完整的堆棧跟蹤。 – Philipp