Exception in thread 'Main'
Rohit-Metapercept opened this issue · 8 comments
Hi Sir ,
I am having an exception error when running the program
Exception in thread "main" jlibs.core.lang.ImpossibleException: java.lang.ClassCastException: org.apache.xerces.dom.DOMXSImplementationSourceImpl cannot be cast to org.w3c.dom.DOMImplementationSource
at jlibs.xml.xsd.XSParser.(XSParser.java:53)
at jlibs.xml.xsd.XSParser.(XSParser.java:44)
at csvconverter.xsdconv.main(xsdconv.java:17)
Caused by: java.lang.ClassCastException: org.apache.xerces.dom.DOMXSImplementationSourceImpl cannot be cast to org.w3c.dom.DOMImplementationSource
at org.w3c.dom.bootstrap.DOMImplementationRegistry.newInstance(DOMImplementationRegistry.java:187)
at jlibs.xml.xsd.XSParser.(XSParser.java:51)
... 2 more
Please suggest me where I am going wrong.
This is the java code:-
package csvconverter;
import jlibs.xml.xsd.XSParser;
import javax.xml.namespace.QName;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.stream.StreamResult;
import org.apache.xerces.xs.*;
import jlibs.xml.xsd.XSInstance;
import jlibs.xml.sax.XMLDocument;
public class xsdconv {
@SuppressWarnings("unused")
public static void main (String[] args){
XSModel xsModel = new XSParser().parse("C:\\Users\\Admin\\Desktop\\out.xsd");
XSInstance xsInstance = new XSInstance();
xsInstance.minimumElementsGenerated = 2;
xsInstance.maximumElementsGenerated = 4;
xsInstance.generateOptionalElements = Boolean.TRUE; // null means random
QName rootElement = new QName("http://jlibs.org", "PurchaseOrder");
XMLDocument sampleXml = null;
try {
sampleXml = new XMLDocument(new StreamResult(System.out), true, 4, null);
} catch (TransformerConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
xsInstance.generate(xsModel, rootElement, sampleXml);
}
}
seems you are not using maven.
you should have following in your classpath:
http://central.maven.org/maven2/xerces/xercesImpl/2.11.0/xercesImpl-2.11.0.jar
http://central.maven.org/maven2/xml-apis/xml-apis/1.4.01/xml-apis-1.4.01.jar
I had imported those jar files , still I am facing the same error. And how to do it from command prompt . I am unable to understand that also.
I tried the following with java version "1.7.0_80"
. and it works fine
curl -O http://central.maven.org/maven2/in/jlibs/jlibs-xsd/2.2.1/jlibs-xsd-2.2.1.jar
curl -O http://central.maven.org/maven2/in/jlibs/jlibs-xml/2.2.1/jlibs-xml-2.2.1.jar
curl -O http://central.maven.org/maven2/in/jlibs/jlibs-core/2.2.1/jlibs-core-2.2.1.jar
curl -O http://central.maven.org/maven2/in/jlibs/jlibs-visitor/2.2.1/jlibs-visitor-2.2.1.jar
curl -O http://central.maven.org/maven2/xerces/xercesImpl/2.11.0/xercesImpl-2.11.0.jar
curl -O http://central.maven.org/maven2/xml-apis/xml-apis/1.4.01/xml-apis-1.4.01.jar
mkdir classes
javac -d classes -classpath jlibs-core-2.2.1.jar:jlibs-visitor-2.2.1.jar:jlibs-xml-2.2.1.jar:jlibs-xsd-2.2.1.jar:xercesImpl-2.11.0.jar:xml-apis-1.4.01.jar xsdconv.java
java -classpath classes:jlibs-core-2.2.1.jar:jlibs-visitor-2.2.1.jar:jlibs-xml-2.2.1.jar:jlibs-xsd-2.2.1.jar:xercesImpl-2.11.0.jar:xml-apis-1.4.01.jar csvconverter.xsdconv
This is my code java code:
package csvconverter;
import javax.xml.namespace.QName;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.stream.StreamResult;
import org.apache.xerces.xs.XSModel;
import jlibs.xml.sax.XMLDocument;
import jlibs.xml.xsd.XSInstance;
public class xsdconv {
public static void main (String[] args) throws TransformerConfigurationException{
xsdconv xsModel = new xsdconv().parse("C:\\Users\\Admin\\Desktop\\out.xsd");
XSInstance xsInstance = new XSInstance();
xsInstance.minimumElementsGenerated = 2;
xsInstance.maximumElementsGenerated = 4;
xsInstance.generateOptionalElements = Boolean.TRUE;
QName rootElement = new QName("", "out");
XMLDocument sampleXml = new XMLDocument(new StreamResult(System.out), true, 4, null);
xsInstance.generate((XSModel) xsModel, rootElement, sampleXml);
}
private xsdconv parse(String string) {
// TODO Auto-generated method stub
return null;
}
}
and now the exception is this
Exception in thread "main" java.lang.NullPointerException
at jlibs.xml.xsd.XSInstance.generate(XSInstance.java:98)
at jlibs.xml.xsd.XSInstance.generate(XSInstance.java:93)
at csvconverter.xsdconv.main(xsdconv.java:31)
the method parse(string) is returning null.
I think the syntax is correct. Then why it is so ?
i am facing the same issue
Caused by: java.lang.ClassCastException: org.apache.xerces.dom.DOMXSImplementationSourceImpl cannot be cast to org.w3c.dom.DOMImplementationSource
at org.w3c.dom.bootstrap.DOMImplementationRegistry.newInstance(DOMImplementationRegistry.java:187)
at org.fit.pdfdom.PDFDomTree.writeText(PDFDomTree.java:188)
... 2 mo