2013-07-08 23 views
0

我正在一個模塊需要在xlsx文件中讀取/寫入的應用程序中工作。 我已經在我的項目中導入了Poi.example 3.9和xml_beans jar。 但仍然在代碼中給出NoClassDefFoundError的錯誤。 這裏是我的代碼: -在android中的xlsx文件中讀/寫: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(); 
      } 
+0

[NoClassDefFoundError](http://stackoverflow.com/a/17106357/2194831)的解決方案。 請求之前搜索... – Krrishnaaaa

+0

也添加錯誤堆棧。 –

回答

1

刪除已添加的庫,並從性能也刪除。現在再次導入該jar。清理項目並嘗試運行。

+0

,但我仍然得到「ClassNotFoundException」.. – user2560188

+1

請檢查我提供的連結。 –

0

如果使用的是Eclipse,然後就在你的項目從package explorer --> Build Path --> Configure build path --> Order and Export --> Check the Android private libraries also your jar file.

點擊我希望這會幫助你。