我得到這個例外的NoClassDefFoundError脫穎而出
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/xmlbeans/XmlException at com.restcalls.JSONtoCSV.main(JSONtoCSV.java:176)
當我試圖將csv
文件轉換爲excel
文件。 此行似乎是導致問題 - XSSFWorkbook workBook = new XSSFWorkbook();
。
我已經添加了最新的POI jar
- 3.17,這是我的代碼:
String xlsxFileAddress = "C:/Users/xxxxx/REST/exports/test.xlsx"; //xlsx file address
System.out.println("here 0");
XSSFWorkbook workBook = new XSSFWorkbook();
System.out.println("here 0.1");
XSSFSheet sheet = workBook.createSheet("sheet1");
System.out.println("here 1");
String currentLine=null;
int RowNum=0;
BufferedReader br = new BufferedReader(new FileReader(csvFileAddress));
System.out.println("here 2: "+br);
while ((currentLine = br.readLine()) != null) {
String str[] = currentLine.split(",");
RowNum++;
XSSFRow currentRow=sheet.createRow(RowNum);
for(int i=0;i<str.length;i++){
currentRow.createCell(i).setCellValue(str[i]);
}
}
FileOutputStream fileOutputStream = new FileOutputStream(xlsxFileAddress);
workBook.write(fileOutputStream);
fileOutputStream.close();
System.out.println("Done");
https://mvnrepository.com/artifact/org.apache.xmlbeans/xmlbeans/2.5。當你搜索類的maven依賴時,0是第一個發現。 – chillworld
@chillworld謝謝!我添加了xmlbeans-2.5.0 jar和poi-ooxml-schemas jar,但是現在我得到了下面的異常:線程「main」中的異常java.lang.NoClassDefFoundError:org/apache/poi/POIXMLTypeLoader \t at org.openxmlformats.schemas.spreadsheet.xml.x2006.main.CTWorkbook $ Factory.newInstance(Unknown Source) \t at org.apache.poi.xssf.usermodel.XSSFWorkbook.onWorkbookCreate(XSSFWorkbook.java:248) –
https:// mvnrepository.com/artifact/org.apache.poi/poi-ooxml =>只要去谷歌,複製你的類到谷歌搜索並添加mvn。通常情況下(例外情況存在),你將在maven中獲得正確的依賴關係,只需選擇正確的版本 – chillworld