Android excel文件读取引发异常

时间:2013-07-25 15:38:47

标签: android apache-poi

我正在使用Apache POI库读取android上的xlsx文件。这引发了非常奇怪的错误。 我的代码在下面给出了任何帮助将更加欣赏。

package com.xlsx;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import android.content.Context;

import com.log.UtilityLogCat;

public class ReadXLSXInputDB {

public ReadXLSXInputDB(Context context, String fileName) {
    readXlsx(context, fileName);

}

private void readXlsx(Context context, String fileName) {
    try {
        InputStream inputStream = context.getAssets().open(fileName);

        Workbook workbook = new XSSFWorkbook(inputStream);
        UtilityLogCat.LogCatVerbose("XLSX Sheet Name",
                workbook.getSheetName(0));
        Sheet sheet = workbook.getSheet("0");
        for (Row row : sheet) {
            for (Cell cell : row) {
                UtilityLogCat.LogCatVerbose("Cell",
                        cell.getStringCellValue());

            }
        }

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

}

引发异常。

    07-25 21:28:18.348: E/AndroidRuntime(2909): FATAL EXCEPTION: main
07-25 21:28:18.348: E/AndroidRuntime(2909): java.lang.IllegalStateException: Could not         execute method of the activity
07-25 21:28:18.348: E/AndroidRuntime(2909):     at     android.view.View$1.onClick(View.java:2072)
07-25 21:28:18.348: E/AndroidRuntime(2909):     at android.view.View.performClick(View.java:2408)
07-25 21:28:18.348: E/AndroidRuntime(2909):     at android.view.View$PerformClick.run(View.java:8816)
07-25 21:28:18.348: E/AndroidRuntime(2909):     at android.os.Handler.handleCallback(Handler.java:587)
07-25 21:28:18.348: E/AndroidRuntime(2909):     at android.os.Handler.dispatchMessage(Handler.java:92)
07-25 21:28:18.348: E/AndroidRuntime(2909):     at android.os.Looper.loop(Looper.java:123)
07-25 21:28:18.348: E/AndroidRuntime(2909):     at android.app.ActivityThread.main(ActivityThread.java:4627)
07-25 21:28:18.348: E/AndroidRuntime(2909):     at java.lang.reflect.Method.invokeNative(Native Method)
07-25 21:28:18.348: E/AndroidRuntime(2909):     at java.lang.reflect.Method.invoke(Method.java:521)
07-25 21:28:18.348: E/AndroidRuntime(2909):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-25 21:28:18.348: E/AndroidRuntime(2909):     at     com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-25 21:28:18.348: E/AndroidRuntime(2909):     at     dalvik.system.NativeStart.main(Native Method)
07-25 21:28:18.348: E/AndroidRuntime(2909): Caused by: java.lang.reflect.InvocationTargetException
07-25 21:28:18.348: E/AndroidRuntime(2909):     at com.apnfinder.APNSettingActivity.onApnSettingChanged(APNSettingActivity.java:131)
07-25 21:28:18.348: E/AndroidRuntime(2909):     at java.lang.reflect.Method.invokeNative(Native Method)
07-25 21:28:18.348: E/AndroidRuntime(2909):     at     java.lang.reflect.Method.invoke(Method.java:521)
07-25 21:28:18.348: E/AndroidRuntime(2909):     at android.view.View$1.onClick(View.java:2067)
07-25 21:28:18.348: E/AndroidRuntime(2909):     ... 11 more
07-25 21:28:18.348: E/AndroidRuntime(2909): Caused by: java.lang.VerifyError:     org.apache.poi.xssf.usermodel.XSSFWorkbook
07-25 21:28:18.348: E/AndroidRuntime(2909):     at com.xlsx.ReadXLSXInputDB.readXlsx(ReadXLSXInputDB.java:28)
07-25 21:28:18.348: E/AndroidRuntime(2909):     at com.xlsx.ReadXLSXInputDB.<init>(ReadXLSXInputDB.java:20)
07-25 21:28:18.348: E/AndroidRuntime(2909):     ... 15 more

任何帮助都会更有意义。

0 个答案:

没有答案