Java - 无法加载文件 NoClassDefFoundError

Java - Trouble loading file NoClassDefFoundError

已解决:我需要添加另一个文件夹中的另一个 jar 文件

我的所有代码都在下面。它来自 this 网站。我已经阅读了多个加载 XSSF 文件的示例,但我仍然遇到同样的错误。我所有的导入都是正确的,但我唯一的猜测是我的文件路径。但它似乎是正确的,没有给我错误

package testcode;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;


import java.util.Iterator;

import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class TestCode {

public static void main( String[] args ) throws IOException {
        InputStream ExcelFileToRead = new FileInputStream("C:/Users/[name]/Desktop/Book1.xlsx");
        XSSFWorkbook  wb = new XSSFWorkbook(ExcelFileToRead);

        XSSFWorkbook test = new XSSFWorkbook(); 

        XSSFSheet sheet = wb.getSheetAt(0);
        XSSFRow row; 
        XSSFCell cell;

        Iterator rows = sheet.rowIterator();

        while ( rows.hasNext() ) {
            row = ( XSSFRow ) rows.next();
            Iterator cells = row.cellIterator();
            while( cells.hasNext() ) {
                cell = ( XSSFCell ) cells.next();

                if ( cell.getCellType() == XSSFCell.CELL_TYPE_STRING ) {
                    System.out.print( cell.getStringCellValue() + " " );
                }
                else if( cell.getCellType() == XSSFCell.CELL_TYPE_NUMERIC ) {
                    System.out.print( cell.getNumericCellValue() + " " );
                }
                else {

                }
            }
            System.out.println();
        }
}

错误信息:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/xmlbeans/XmlException at testcode.TestCode.main(TestCode.java:20) Caused by: java.lang.ClassNotFoundException: org.apache.xmlbeans.XmlException at java.net.URLClassLoader.run(Unknown Source) at java.net.URLClassLoader.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) 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

NoClassDefFoundError。当存在 class 文件或 api 您的代码所依赖的文件在编译时存在但在运行时未找到时,会遇到此异常。 请检查运行时可用的 jar 或比较运行时和编译依赖项。