在android中的xlsx文件中读/写:NoClassDefFoundError

时间:2013-07-08 09:42:49

标签: android file xlsx fileinputstream

我正在一个应用程序中,模块需要在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();
            }

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

如果您使用的是eclipse,请在package explorer --> Build Path --> Configure build path --> Order and Export --> Check the Android private libraries also your jar file.

中右键单击您的项目

我希望这会对你有所帮助。