java.lang.ClassNotFoundException: org.apache.xmlbeans.XmlObject
java.lang.ClassNotFoundException: org.apache.xmlbeans.XmlObject

Symptom)
When I tried creating workbook instance, I got error message like below.
Exception
in thread "main" java.lang.NoClassDefFoundError:
org/apache/xmlbeans/XmlObject
at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:211)
at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:188)
at CliMain.main(CliMain.java:32)
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)
... 3 more
|
Code:
package
com.suresofttech.car.provautosar.ui;
import
java.io.File;
import
java.io.IOException;
import
java.util.Scanner;
import
org.apache.poi.EncryptedDocumentException;
import
org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import
org.apache.poi.ss.usermodel.Sheet;
import
org.apache.poi.ss.usermodel.Workbook;
import
org.apache.poi.ss.usermodel.WorkbookFactory;
public
class CliMain {
public static void main(String[] args) throws EncryptedDocumentException, InvalidFormatException,
IOException {
Scanner scanner = null;
File excelFile = null;
Workbook workbook = null;
Sheet sheet = null;
String inputMessage = null;
String filePath = null;
int totalRowNum = 0;
int firstRowIndex = 0;
int lastRowIndex = 0;
// input excel file directory path
scanner = new Scanner(System.in);
inputMessage = scanner.nextLine();
filePath = inputMessage;
scanner.close();
// convert it to excel workbook instance
excelFile = new File(filePath);
workbook = WorkbookFactory.create(excelFile);
// parse workbook
sheet = workbook.getSheetAt(0);
totalRowNum = sheet.getPhysicalNumberOfRows();
firstRowIndex = sheet.getFirstRowNum();
lastRowIndex = sheet.getLastRowNum();
System.out.println(totalRowNum);
for(int i = firstRowIndex ; i < lastRowIndex ; i++){
sheet.getRow(i);
}
}
}
|
Root Cause)
I forgot "xmlbeans-2.6.0.jar" by mistake when importing POI API library to the project.
Solution)

Just import "xmlbeans-2.6.0.jar" into the project workpath.
Comments
Post a Comment