Исключение в потоке “основной” java.lang. NoClassDefFoundError: org/apache/xmlbeans/XmlException

Я должен считать xls файл в Java. Я использовал пои 3.6 для чтения xls файла в Eclipse. Но я получаю эту ОШИБКУ "Исключение в потоке "основной" java.lang. NoClassDefFoundError: org/apache/xmlbeans/XmlException в ReadExcel2.main(ReadExcel2.java:38)".

Я добавил следующие банки 1) poi-3.6-20091214.jar 2) poi-contrib-3.6-20091214.jar 3) poi-examples-3.6-20091214.jar 4) poi-ooxml-3.6-20091214.jar 5) poi-ooxml-schemas-3.6-20091214.jar 6), poi-scratchpad-3.6-20091214.jar

Ниже код, который я использую:

import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import java.util.ArrayList;
public class ReadExcel {

    public static void main(String[] args) throws Exception {
        //
        // An excel file name. You can create a file name with a full path
        // information.
        //
        String filename = "C:\\myExcel.xl";
        //
        // Create an ArrayList to store the data read from excel sheet.
        //
        List sheetData = new ArrayList();

        FileInputStream fis = null;
        try {
            //
            // Create a FileInputStream that will be use to read the excel file.
            //
            fis = new FileInputStream(filename);

            //
            // Create an excel workbook from the file system.
            //
           // HSSFWorkbook workbook = new HSSFWorkbook(fis);
            Workbook workbook = new XSSFWorkbook(fis);  

            //
            // Get the first sheet on the workbook.
            //
            Sheet sheet = workbook.getSheetAt(0);

            //
            // When we have a sheet object in hand we can iterator on each
            // sheet's rows and on each row's cells. We store the data read
            // on an ArrayList so that we can printed the content of the excel
            // to the console.
            //
            Iterator rows = sheet.rowIterator();
            while (rows.hasNext()) {
                Row row = (XSSFRow) rows.next();
                Iterator cells = row.cellIterator();

                List data = new ArrayList();
                while (cells.hasNext()) {
                    Cell cell = (XSSFCell) cells.next();
                    data.add(cell);
                }

                sheetData.add(data);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (fis != null) {
                fis.close();
            }
        }

        showExelData(sheetData);
    }
    private static void showExelData(List sheetData) {
        //
        // Iterates the data and print it out to the console.
        //
        for (int i = 0; i < sheetData.size(); i++) {
            List list = (List) sheetData.get(i);
            for (int j = 0; j < list.size(); j++) {
                Cell cell = (XSSFCell) list.get(j);
                System.out.print(cell.getRichStringCellValue().getString());
                if (j < list.size() - 1) {
                    System.out.print(", ");
                }
            }
            System.out.println("");
        }
    }
}

Помогите. спасибо в ожидании, С уважением, Dheeraj!

16
задан Ken 1 July 2013 в 10:20
поделиться

2 ответа

Вам нужно xmlbeans в пути к классам.

NoClassDefFoundError означает, что:

Определение искомого класса существовало, когда выполняемый в данный момент класс был скомпилирован, но определение больше не может быть найдено.

В следующий раз, когда вы получите подобное исключение, это означает, что для какой-то сторонней библиотеки требуется другая сторонняя библиотека. Затем используйте Google (или любые другие средства), чтобы узнать, какая это библиотека. Кроме того, большинство библиотек четко указывают в своей документации и / или дистрибутивах, каковы их зависимости.

37
ответ дан 30 November 2019 в 16:00
поделиться

JarFinder предлагает XMLBeans.jar

7
ответ дан 30 November 2019 в 16:00
поделиться
Другие вопросы по тегам:

Похожие вопросы: