在Java Noclassdeffounderror中写入Excel

发布于 2025-01-21 07:54:12 字数 925 浏览 2 评论 0原文

当我尝试将数据添加到Java Ant中的Excel时,它显示noclassDeffoundError,即使我导入了Apache POI的所有JAR文件。这是错误:

线程中的异常“ main” java.lang.noclassdeffounderror:org/apache/commons/io/output/unsynchronized bytearrayoutputstream

这是我尝试的代码:

XSSFWorkbook wb = new XSSFWorkbook();
    
    XSSFSheet sheet = wb.createSheet("Sheet1");
    
    XSSFRow row = sheet.createRow(0);
    
    Cell cell0 = row.createCell(0);
    cell0.setCellValue("HelloWorld!");
    
    
    try{
        FileOutputStream out = new FileOutputStream(new File("Result.xlsx"));
        wb.write(out);
        out.close();
        System.out.println("Done");
    }catch(FileNotFoundException e){
        e.printStackTrace();
    }catch(IOException e){
        e.printStackTrace();
    }

这些是JAR导入的文件: “

When I try to add data to Excel from Java Ant, it shows NoClassDefFoundError, even that I imported all Jar files of Apache Poi. This is the Error:

Exception in thread "main" java.lang.NoClassDefFoundError:org/apache/commons/io/output/UnsynchronizedByteArrayOutputStream

This is the code i tried:

XSSFWorkbook wb = new XSSFWorkbook();
    
    XSSFSheet sheet = wb.createSheet("Sheet1");
    
    XSSFRow row = sheet.createRow(0);
    
    Cell cell0 = row.createCell(0);
    cell0.setCellValue("HelloWorld!");
    
    
    try{
        FileOutputStream out = new FileOutputStream(new File("Result.xlsx"));
        wb.write(out);
        out.close();
        System.out.println("Done");
    }catch(FileNotFoundException e){
        e.printStackTrace();
    }catch(IOException e){
        e.printStackTrace();
    }

These are Jar imported files:
Libraries Classpath

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

树深时见影 2025-01-28 07:54:12

问题解决了!似乎我还需要在导入JAR文件之后添加依赖性。xml!

Problem solved! It seems i needed to add dependecy to build.xml also after importing jar files!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文