我正在使用 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
任何帮助都会更有价值。