0

我正在一个模块需要在 xlsx 文件中读/写的应用程序中工作。我已经在我的项目中导入了 Poi.example 3.9 和 xml_beans jar。NoClassDefFoundError但它仍然在代码中给出错误。这是我的代码:-

try{    


    FileInputStream file = new FileInputStream(new File("< path of excel file.....xlsx"));

    XSSFWorkbook wb = new XSSFWorkbook(file);

    XSSFSheet sheet = wb.getSheetAt(0);

    //iterate through each row from first sheet
    Iterator<Row> rowIterator = sheet.iterator();
    while(rowIterator.hasNext()){
        Row row = rowIterator.next();

        //Fore each row iterate through each column
        Iterator<Cell> cellIterator = row.cellIterator();
        while(cellIterator.hasNext()){
            Cell cell = cellIterator.next();


            switch (cell.getCellType()){
                case Cell.CELL_TYPE_BOOLEAN:
                    System.out.print(cell.getBooleanCellValue() + "\t\t");
                    break;

                case Cell.CELL_TYPE_NUMERIC:
                    System.out.print(cell.getNumericCellValue() + "\t\t");
                    break;

                case Cell.CELL_TYPE_STRING:
                    System.out.print(cell.getStringCellValue() + "\t\t");
                    break; 

            }

        }

        System.out.println("");
    }

    file.close();
    FileOutputStream out = new FileOutputStream (new File("< path of excel file.....xlsx"));
    wb.write(out);
    out.close();

            } catch(FileNotFoundException e){
                e.printStackTrace();
            } catch (IOException e){
                e.printStackTrace();
            }
4

2 回答 2

1

删除您添加的库并从属性中删除。现在再次导入 jar。清理项目并尝试运行。

于 2013-07-08T09:55:07.857 回答
0

如果您使用的是 Eclipse,请右键单击您的项目package explorer --> Build Path --> Configure build path --> Order and Export --> Check the Android private libraries also your jar file.

我希望这能帮到您。

于 2013-07-08T10:03:03.967 回答