I am trying to create a .xlsx file using Apache POI. This is my code:
FileOutputStream outputStream1=null;
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet("data");
try {
target.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
outputStream1 = new FileOutputStream(Environment.getExternalStorageDirectory().getAbsolutePath()+"/file_A/"+"test_Ab"+".xlsx");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for(int i=0;i<iteration;i++)
{
XSSFRow row = sheet.createRow(i);
Cell cell = row.createCell(0);
cell.setCellValue("dsfasdf");
}
try {
FileOutputStream out = new FileOutputStream(target);
workbook.write(out);
out.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
I get the following exception when run the code:
02-19 11:48:13.387: E/AndroidRuntime(18736): FATAL EXCEPTION: main
02-19 11:48:13.387: E/AndroidRuntime(18736): java.lang.NoClassDefFoundError: org.apache.poi.xssf.usermodel.XSSFWorkbook
02-19 11:48:13.387: E/AndroidRuntime(18736): at com.example.filegenerator.MainActivity$2.onClick(MainActivity.java:248)
02-19 11:48:13.387: E/AndroidRuntime(18736): at android.view.View.performClick(View.java:4101)
02-19 11:48:13.387: E/AndroidRuntime(18736): at android.view.View$PerformClick.run(View.java:17088)
02-19 11:48:13.387: E/AndroidRuntime(18736): at android.os.Handler.handleCallback(Handler.java:615)
02-19 11:48:13.387: E/AndroidRuntime(18736): at android.os.Handler.dispatchMessage(Handler.java:92)
02-19 11:48:13.387: E/AndroidRuntime(18736): at android.os.Looper.loop(Looper.java:153)
02-19 11:48:13.387: E/AndroidRuntime(18736): at android.app.ActivityThread.main(ActivityThread.java:5096)
02-19 11:48:13.387: E/AndroidRuntime(18736): at java.lang.reflect.Method.invokeNative(Native Method)
02-19 11:48:13.387: E/AndroidRuntime(18736): at java.lang.reflect.Method.invoke(Method.java:511)
02-19 11:48:13.387: E/AndroidRuntime(18736): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
02-19 11:48:13.387: E/AndroidRuntime(18736): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
02-19 11:48:13.387: E/AndroidRuntime(18736): at dalvik.system.NativeStart.main(Native Method)
I am using the poi-3.7.jar. What is the problem here?