当我尝试使用usig XSSF工作簿创建xlsx文件时,发生以下错误。我已经为人们看到了更多的答案,但是其中没有一个针对我的问题的答案。
我的代码的一小段处理了这个问题(这是导致错误的直接原因):
public static void Reader(File file) throws IOException, InvalidFormatException {
FileInputStream fis = new FileInputStream(file);
// Creating a Workbook from an Excel file (.xlsx)
XSSFWorkbook workbook = new XSSFWorkbook(fis);
// Getting the Sheet at index zero
Sheet sheet = workbook.getSheetAt(0);
// Create a DataFormatter to format and get each cell's value as String
DataFormatter dataFormatter = new DataFormatter();
for(int i = 1; i < sheet.getLastRowNum(); i++) {
Row row = sheet.getRow(i);
for(int j = 0; j < row.getLastCellNum(); j++) {
Cell cell = row.getCell(j);
switch(j) {
case 0:
debiteurList.add(cell.toString());
break;
case 3:
losnaamList.add(cell.toString());
break;
case 5:
losadresList.add(cell.toString());
break;
case 7:
lospostcodeList.add(cell.toString());
break;
case 8:
losplaatsList.add(cell.toString());
break;
case 9:
loslandList.add(cell.toString());
break;
case 11:
totallinesList.add(cell.toString());
break;
case 12:
opmerkingList.add(cell.toString());
break;
case 14:
rijtypeList.add(cell.toString());
break;
case 15:
beginlostijdList.add(cell.toString());
break;
case 16:
eindlostijdList.add(cell.toString());
break;
}
}
}
System.out.println("successfully read xlsx");
workbook.close();
}
这是错误:
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/apache/xmlbeans/XmlObject
at planning.pyxislijst.Reader.Reader(Reader.java)
at planning.pyxislijst.Reader.Runner(Reader.java)
at client.Client$4.actionPerformed(Client.java)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.AbstractButton.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.apache.xmlbeans.XmlObject
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 41 more
答案 0 :(得分:0)