如何解决java.lang.VerifyError:组织/阿帕奇/ POI / XSSF /的usermodel / XSSFWorkbook?如何解决、阿帕奇、组织、lang

2023-09-07 15:30:46 作者:天塌了 | 自己顶着

我试图读取资产文件夹中的xlsx档案。我下面例外收到

  

十月5日至十六日:12:05.613:E / AndroidRuntime(2915):致命异常:主要      十月5日至16日:12:05.613:E / AndroidRuntime(2915):java.lang.VerifyError:组织/阿帕奇/ POI / XSSF /的usermodel / XSSFWorkbook

此异常之前,我收到了一些警告也是这样,

  

找不到方法  org.openxmlformats.schemas.s preadsheetml.x2006.main.WorkbookDocument $ Factory.parse,  从方法引用  org.apache.poi.xssf.usermodel.XSSFWorkbook.onDocumentRead

  

VFY:无法解决的异常类3612  (Lorg /阿帕奇/的XMLBeans / XmlException;)

我添加POI库3.12在我的应用程序,库截图如下,

和我已经检查POI-3.12和POI-OOXML-3.12 jar文件排序和导出,截图如下,

我用低于code,

  InputStream为= context.getAssets()开(sample.xlsx))。        XSSFWorkbook工作簿=新XSSFWorkbook(是);        XSSFSheet片= workbook.getSheetAt(0);        细胞细胞= sheet.getRow(0).getCell(0);        字符串值= cell.getStringCellValue()+; 

我要读写.XLSX和.xls文件。如何解决这个问题?

先谢谢了。

解决方案

杉杉您应该连接到你的项目,这些罐子。

然后用这个code阅读

 公共静态无效readXLSXFile()抛出IOException异常    {        InputStream的ExcelFileToRead =新的FileInputStream(C:/Test.xlsx);        XSSFWorkbook WB =新XSSFWorkbook(ExcelFileToRead);        XSSFWorkbook测试=新XSSFWorkbook();        XSSFSheet片= wb.getSheetAt(0);        XSSFRow排;        XSSFCell细胞;        迭代行= sheet.rowIterator();        而(rows.hasNext())        {            行=(XSSFRow)rows.next();            迭代器单元= row.cellIterator();            而(cells.hasNext())            {                细胞=(XSSFCell)cells.next();                如果(cell.getCellType()== XSSFCell.CELL_TYPE_STRING)                {                    System.out.print(cell.getStringCellValue()+);                }                否则如果(cell.getCellType()== XSSFCell.CELL_TYPE_NUMERIC)                {                    System.out.print(cell.getNumericCellValue()+);                }                其他                {                    //ü可以亨德尔布尔,公式,错误                }            }            的System.out.println();        }    } 
宝可梦 阿罗拉的嘎啦嘎啦还是很好用 已成为双打里的牌面

I'm trying to read the xlsx file from asset folder. I received below exception,

05-16 10:12:05.613: E/AndroidRuntime(2915): FATAL EXCEPTION: main 05-16 10:12:05.613: E/AndroidRuntime(2915): java.lang.VerifyError: org/apache/poi/xssf/usermodel/XSSFWorkbook

before this exception, I received some warnings also like,

Could not find method org.openxmlformats.schemas.spreadsheetml.x2006.main.WorkbookDocument$Factory.parse, referenced from method org.apache.poi.xssf.usermodel.XSSFWorkbook.onDocumentRead

VFY: unable to resolve exception class 3612 (Lorg/apache/xmlbeans/XmlException;)

I have added poi 3.12 library on my application, libraries screenshot as below,

And I have checked poi-3.12 and poi-ooxml-3.12 jar files in Order and Export, screenshot as below,

I used below code,

        InputStream is = context.getAssets().open("sample.xlsx"));
        XSSFWorkbook workbook = new XSSFWorkbook(is);
        XSSFSheet sheet = workbook.getSheetAt(0);
        Cell cell = sheet.getRow(0).getCell(0);
        String value = cell.getStringCellValue() + "";

I want to read and write the .XLSX and .XLS files. How to resolve this issue?

Thanks in Advance.

解决方案

Firs you should connect to your project these jars.

Then use this code for reading

public static void readXLSXFile() throws IOException
    {
        InputStream ExcelFileToRead = new FileInputStream("C:/Test.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
                {
                    //U Can Handel Boolean, Formula, Errors
                }
            }
            System.out.println();
        }

    }