java.lang.NoClassDefFoundError的同时创造使用Apache POI一个.xlsx文件 [英] java.lang.NoClassDefFoundError while creating a .xlsx file using Apache POI

查看:262
本文介绍了java.lang.NoClassDefFoundError的同时创造使用Apache POI一个.xlsx文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建使用Apache POI一个.xlsx文件。这是我的code:

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

我运行code当出现以下情况例外:

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)

我现在用的是 POI-3.7.jar 。有什么问题吗?

推荐答案

至于详细的的Apache POI组件页面,使用OOXML code XSSF一样,你既需要 POI POI-OOXML 在classpath罐,以及它们的依赖关系。

As detailed on the Apache POI components page, to use the OOXML code like XSSF, you need both the poi and poi-ooxml jars on your classpath, along with their dependencies.

的Apache POI的最新版本,如写作,是3.10。我建议你​​去下载二进制发布包,在那里你会发现所有的POI罐子,以及他们所有的依赖关系。该组件页面会帮助你的工作,你需要的,但是对于XSSF短期工作答案是你基本上需要所有的人!

The latest version of Apache POI, as of writing, is 3.10. I'd suggest you go download the binary release package, in there you'll find all the POI jars, along with all their dependencies. The components page will help you work out which you need, but for working with XSSF the short answer is you'll basically need all of them!

这篇关于java.lang.NoClassDefFoundError的同时创造使用Apache POI一个.xlsx文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆