是什么给java.lang.NoClassDefFoundError的? [英] what give java.lang.NoClassDefFoundError?

查看:220
本文介绍了是什么给java.lang.NoClassDefFoundError的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想读的Excel文件,但给

I want to read excel file but give

    Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/xmlbeans/XmlObject
 at ExcelReader.main(ExcelReader.java:32)
Caused by: java.lang.ClassNotFoundException: org.apache.xmlbeans.XmlObject
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 1 more

请帮助我。
在第一次打开.xlsx文件,然后给第一个表。
在Excel中的最后打印数据上的控制台文件。
PS:我添加POI-OOXML-3.9-20121203.jar到我的项目

please help me. At first open .xlsx file and then give the first sheet. at the end print data of excel file on console. Ps : I add poi-ooxml-3.9-20121203.jar to my project.

    import java.io.File;
    import java.io.FileInputStream;
    import javax.swing.text.html.HTMLDocument.Iterator;
    import org.apache.poi.hssf.usermodel.HSSFSheet;
    import org.apache.poi.hssf.usermodel.HSSFWorkbook;
    import org.apache.poi.ss.usermodel.Cell;
    import org.apache.poi.ss.usermodel.Row;
    import org.apache.poi.xssf.usermodel.XSSFSheet;
    import java.util.*;
    import org.apache.poi.xssf.usermodel.XSSFWorkbook;
    /**
     * @author mohammad hosein
    *
    */
    public class ExcelReader {

/**
 * @param args
 */
public static void main(String[] args) {
    try
    {
    FileInputStream file = new FileInputStream(new File("E:\\test.xlsx"));

    //Get the workbook instance for XLS file 
    XSSFWorkbook workbook = new XSSFWorkbook (file);

    //Get first sheet from the workbook
    XSSFSheet sheet = workbook.getSheetAt(0);

    //Get iterator to all the rows in current sheet
    java.util.Iterator<Row> rowIterator = sheet.iterator();

    while(rowIterator.hasNext())
    {
        Row row = rowIterator.next();
        java.util.Iterator<Cell> cellIterator = row.cellIterator();

        while(cellIterator.hasNext())
        {
            Cell cell = cellIterator.next();
            System.out.print(cell.getStringCellValue() + "\t");
        }
        System.out.println("");
    }
    }
    catch(Exception e)
    {
        System.out.println("EROR!");
    }

    //Get iterator to all cells of current row

}

}

推荐答案

您code是无关紧要的。 的NoClassDefFoundError 发生在这是可以在编译时一类是在运行时不可用。如果你提供了一个完整的堆栈跟踪,再加上还没有被发现的类的实际名称,更precise建议可以给予。

Your code is irrelevant. NoClassDefFoundError happens when a class which was available at compilation time is unavailable at runtime. If you provided a full stacktrace, together with the actual name of the class which has not been found, more precise advice could be given.

这通常当你从用于构建code中的一个不同版本的JAR的运行你code发生。流氓JAR可以从应用程序容器或类似进来,并且比你适当的JAR更早在classpath中放置。

Typically this happens when you are running your code with a different version of a JAR from the one used to build the code. A rogue JAR may come in from an application container or similar, and be placed earlier on the classpath than your proper JAR.

由于您已经添加了堆栈跟踪,而是缺乏的Apache POI的传递依赖:XMLBeans的。您可能会丢失这个JAR在运行时。这一切都取决于你究竟是如何运行项目。

Given the stacktrace you have added, you are lacking a transitive dependency of Apache POI: XMLBeans. You may be missing this JAR at runtime. This all depends on how exactly you are running your project.

这篇关于是什么给java.lang.NoClassDefFoundError的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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