我正在開發一個可以將視頻發送到php服務器的java應用程序。 我已經在android上完成了它,下面的代碼在android上工作完美,但現在當我嘗試在純java(而不是android)中的代碼時,我得到了異常。 這是我的Java桌面代碼,上傳視頻到PHP將視頻從java上傳到php服務器時出錯
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(
"http://b....vedioup.php");
FileBody filebodyVideo = new FileBody(new File(Path));
StringBody title = new StringBody("Filename: " + Path);
StringBody description = new StringBody(
"This is a description of the video");
MultipartEntity reqEntity = new MultipartEntity();
reqEntity.addPart("videoFile", filebodyVideo);
reqEntity.addPart("title", title);
reqEntity.addPart("description", description);
httppost.setEntity(reqEntity);
// DEBUG
System.out
.println("executing request " + httppost.getRequestLine());
HttpResponse response = httpclient.execute(httppost);
HttpEntity resEntity = response.getEntity();
// DEBUG
System.out.println(response.getStatusLine());
if (resEntity != null) {
System.out.println(EntityUtils.toString(resEntity));
} // end if
if (resEntity != null) {
resEntity.consumeContent();
} // end if
httpclient.getConnectionManager().shutdown();
}
,這是在控制檯輸出。
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at org.apache.http.impl.client.AbstractHttpClient.<init>(AbstractHttpClient.java:187)
at org.apache.http.impl.client.DefaultHttpClient.<init>(DefaultHttpClient.java:146)
at BlankFoem.uploadFile(BlankFoem.java:351)
很明顯,它沒有找到類的例外,但我該如何解決它。
感謝
該錯誤主要講述一個缺少的類,這個類是在一個lib jar我認爲你需要在你的類路徑中包含'apache commons:logging' jar – Yazan 2014-11-08 10:37:28
是啊@Yazan你是對的。謝謝 – 2014-11-08 10:56:17