简体   繁体   中英

Exception in thread “AWT-EventQueue-0” java.lang.NoSuchMethodError: org.apache.xmlbeans.XmlOptions.put(Ljava/lang/Object;)V

My code line causing error:

if(!refreshInputStream())
    return;
Workbook workbook = new org.apache.poi.xssf.usermodel.XSSFWorkbook(datasetInputStream);

The refreshInputStream function:

private boolean refreshInputStream(){
    if(this.datasetInputStream == null){
        if(this.dataset.length() <= 0){
            return  false;
        }
        try {
            datasetInputStream = new FileInputStream(new File(dataset));
        }catch (Exception ex){
        }
    }
    return true;
}

Class variables:

public String dataset;
private InputStream datasetInputStream;

There is also a function that stores the location(like C:\Users\Jaysmito\68774.xlsx ) of the file in dataset Variable before reaching the line in which the error is happening.

Error:

Exception in thread "AWT-EventQueue-0" java.lang.NoSuchMethodError: org.apache.xmlbeans.XmlOptions.put(Ljava/lang/Object;)V
    at org.apache.poi.xssf.model.SharedStringsTable.<clinit>(SharedStringsTable.java:94)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:56)
    at org.apache.poi.ooxml.POIXMLFactory.createDocumentPart(POIXMLFactory.java:63)
    at org.apache.poi.ooxml.POIXMLDocumentPart.read(POIXMLDocumentPart.java:648)
    at org.apache.poi.ooxml.POIXMLDocument.load(POIXMLDocument.java:180)
    at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:286)
    at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:307)
    at App.searchLocal(App.java:238)
    at App.actionPerformed(App.java:207)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
    at java.awt.Component.processMouseEvent(Component.java:6539)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
    at java.awt.Component.processEvent(Component.java:6304)
    at java.awt.Container.processEvent(Container.java:2239)
    at java.awt.Component.dispatchEventImpl(Component.java:4889)
    at java.awt.Container.dispatchEventImpl(Container.java:2297)
    at java.awt.Component.dispatchEvent(Component.java:4711)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4904)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4535)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4476)
    at java.awt.Container.dispatchEventImpl(Container.java:2283)
    at java.awt.Window.dispatchEventImpl(Window.java:2746)
    at java.awt.Component.dispatchEvent(Component.java:4711)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:760)
    at java.awt.EventQueue.access$500(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:709)
    at java.awt.EventQueue$3.run(EventQueue.java:703)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:84)
    at java.awt.EventQueue$4.run(EventQueue.java:733)
    at java.awt.EventQueue$4.run(EventQueue.java:731)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:730)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

File I am trying to open.

https://rbidocs.rbi.org.in/rdocs/content/docs/68774.xlsx

I am using Apache POI version 4.0.0. I removed the unnecessary GUI code so that the problem is easier to read. What is the problem with my code, and how can I fix it?

My dependencies:

  1. xmlbeans-4.0.0.jar

  2. poi.ooxml-schemas-4.1.2.jar

  3. commons-codec-1.10.jar

  4. commons-compress-1.18.jar

  5. commons-collections4-4.2.jar

  6. curvesapi-1.04.jar

  7. poi-4.0.0.jar

  8. poi-ooxml-4.0.0.jar

The problem is that your project depends on xmlbeans-4.0.0.jar. Apache POI 4.0.0 requires XMLBeans version 3.0.1, the XMLBeans 4.0.0 version has incompatible changes and cannot be used with the 4.x versions of Apache POI. You either need to downgrade the XMLBeans dependency to 3.0.1 (or at least a 3.x version), or upgrade Apache POI to 5.0.0.

On a related note, you're mixing versions of POI itself as well. You depend on poi.ooxml-schemas-4.1.2.jar, while all your other POI dependencies are 4.0.0. If you want to use Apache POI 4.x, then use the same 4.x version for all POI dependencies.

In addition, the binary distribution of Apache POI 4.0.0 depends on commons-codec-1.11.jar, not 1.10, and curvesapi-1.05.jar, not 1.04; though those versions are likely compatible.

If this is a new project, I recommend you start with Apache POI 5.0.0, available at https://poi.apache.org/ . Use the dependencies included in the binary distribution (in the lib and ooxml-lib folder of the zip), or better yet, switch to Apache Maven or Gradle, and let that handle your dependencies.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM