NoClassDefFoundError,同时读取Excel工作表数据和打印值我收到以下代码的classnotfound异常:
package practice;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class dataDriven {
public static void main(String[] args) throws FileNotFoundException,IOException
{
FileInputStream fis = new FileInputStream("C://Users//484834//testdata.xlsx");
XSSFWorkbook wb = new XSSFWorkbook(fis);
wb =null;
int sheets = wb.getNumberOfSheets();
System.out.println("Number of sheets is "+sheets);
}
}
输出为:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/collections4/ListValuedMap
at practice.dataDriven.main(dataDriven.java:14)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.collections4.ListValuedMap
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)
... 1 more
似乎您丢失了jar文件。您可以在构建路径中添加commons-collections4-x.jar
。
URL相同为-https://mvnrepository.com/artifact/org.apache.commons/commons-collections4/4.2
希望这可以解决您的问题。