-1

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);
             }
        }
    }
4

1 に答える 1

0

これは、実行時に何らかの形で欠落しているコンパイル時にあるクラスがあることを意味します。コンパイル中にクラスパスを書き留めて、ランタイム環境と比較してください。これは、欠落しているクラスを見つけるのに役立ちます。

于 2013-04-16T12:19:37.753 に答える