0
我有一些代碼誰在netbeans
工作讀取.xlsx文件。我試圖在Android Studio中實現它,但沒有成功到達我的.xlsx文件:我已經將路徑「C \ etc \ etc \」並且不起作用。.xlsx文件在android工作室
我將文件複製到文件夾drawable
,並設置下列變量,但它仍然沒有奏效:
String filename = "renk hex.xlsx";
,我應該把這個.xlsx文件,以達到呢?
我沒有錯誤的代碼,我的應用程序genymotion
停止工作,當我調用負責閱讀此文件的類。
這裏是我的代碼:
String filename = "renk hex.xlsx";
List sheetData = new ArrayList(); // dataItem
FileInputStream fis = null;
try {
fis = new FileInputStream(filename);
XSSFWorkbook workbook = new XSSFWorkbook(fis);
XSSFSheet sheet = workbook.getSheetAt(0);
Iterator rows = sheet.rowIterator();
while (rows.hasNext()) {
XSSFRow row = (XSSFRow) rows.next();
Iterator cells = row.cellIterator();
List data = new ArrayList();
while (cells.hasNext()) {
XSSFCell cell = (XSSFCell) cells.next();
data.add(cell);
}
sheetData.add(data);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (fis != null) {
try {
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
日誌:
Process: hesh.ballc, PID: 3774
java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:3823)
at android.view.View.performClick(View.java:4438)
at android.view.View$PerformClick.run(View.java:18422)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
感謝
如果它停止工作,有可能異常的地方。請分享您的代碼打破的地方... – Tgsmith61591
@ Tgsmith61591這裏是我的代碼 –
@huse_ng請添加您的logcat異常輸出,它將幫助您更準確地找到破解的位置,而不是通過挑選代碼。 – basic