本文介绍了如何解决 java.lang.VerifyError: org/apache/poi/xssf/usermodel/XSSFWorkbook?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从资产文件夹中读取 xlsx 文件.我收到以下异常,

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

05-16 10:12:05.613:E/AndroidRuntime(2915):致命异常:主要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,

  • 我在我的应用程序中添加了 poi 3.12 库,库截图如下,

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

    并且我在Order和Export中检查了poi-3.12和poi-ooxml-3.12 jar文件,截图如下,

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

    我使用了下面的代码,

            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() + "";
    

    我想读取和写入 .XLSX 和 .XLS 文件.如何解决这个问题?

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

    提前致谢.

    推荐答案

    首先你应该将这些 jars 连接到你的项目.

    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();
            }
    
        }
    

    这篇关于如何解决 java.lang.VerifyError: org/apache/poi/xssf/usermodel/XSSFWorkbook?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    08-05 21:41