• Post Reply Bookmark Topic Watch Topic
  • New Topic

JAXBContext.newInstance error while creating the instance of JAXBContext.newInstance  RSS feed

 
premchand Singh
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I have more than 15 pojo classes from which i have to generate xml files,
when i am trying to create instance of JAXBContext to load those classes as below :

JAXBContext.newInstance("com.company.objects.project");
It is showing error like this :

java.lang.NullPointerException
at com.sun.xml.bind.GrammarInfoFacade.getProbePoints(GrammarInfoFacade.java:68)
at com.sun.xml.bind.GrammarInfoFacade.<init>(GrammarInfoFacade.java:38)
at com.sun.xml.bind.GrammarInfoFacade.createGrammarInfoFacade(GrammarInfoFacade.java:110)
at com.sun.xml.bind.DefaultJAXBContextImpl.<init>(DefaultJAXBContextImpl.java:57)
at com.sun.xml.bind.ContextFactory.createContext(ContextFactory.java:27)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

what i am missing in this ..


 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you supposed to use classes from packages beginning com.sun? I can never remember.

Show us the code where the first line in the stack trace shows your code rather than imported code, please.
 
premchand Singh
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am pasting the whole stacktrace :

java.lang.NullPointerException
at com.sun.xml.bind.GrammarInfoFacade.getProbePoints(GrammarInfoFacade.java:68)
at com.sun.xml.bind.GrammarInfoFacade.<init>(GrammarInfoFacade.java:38)
at com.sun.xml.bind.GrammarInfoFacade.createGrammarInfoFacade(GrammarInfoFacade.java:110)
at com.sun.xml.bind.DefaultJAXBContextImpl.<init>(DefaultJAXBContextImpl.java:57)
at com.sun.xml.bind.ContextFactory.createContext(ContextFactory.java:27)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at javax.xml.bind.ContextFinder.newInstance(Unknown Source)
at javax.xml.bind.ContextFinder.newInstance(Unknown Source)
at javax.xml.bind.ContextFinder.find(Unknown Source)
at javax.xml.bind.JAXBContext.newInstance(Unknown Source)
at javax.xml.bind.JAXBContext.newInstance(Unknown Source)
at javax.xml.bind.JAXBContext.newInstance(Unknown Source)
at com.company.glc.util.clarity.mapper.ProjectPojoXMLMapper.createProjectXML(ProjectPojoXMLMapper.java:46)
at com.company.glc.job.InterfaceHandler.process(InterfaceHandler.java:216)
at com.company.glc.job.InterfaceHandler.main(InterfaceHandler.java:360)
Exception in thread "main" com.company.glc.util.clarity.exception.XMLException: Unable to generate Project XML file
at com.company.glc.util.clarity.mapper.ProjectPojoXMLMapper.createProjectXML(ProjectPojoXMLMapper.java:194)
at com.company.glc.job.InterfaceHandler.process(InterfaceHandler.java:216)
at com.company.glc.job.InterfaceHandler.main(InterfaceHandler.java:360)

Lst line of the code is responsible for calling the stacktrace.

 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You appear to have an XMLEception at line 194. Please show us that. Also wrap that line in a try‑catch to confirm the stack trace.
 
premchand Singh
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes i am catching the error in a try catch block like below :

192. } catch (Exception e) {
193. e.printStackTrace();
194. throw new XMLException("Unable to generate Project XML file","XML_PROJECT_NO_XML_GENERATED");
195. }

what you have mentioned in the comment is the same as line no : 194.
 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Comment out the line to throw the new Exception, and are you getting the null Exception there?
So which line in your code produces the null Exception? Is that line 46?
 
premchand Singh
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes after executing line no : 46, it is directly going in catch block.

in line no: 92, and the exception caught is nullPointerException. the same exception is being thrown in next statement using throw statement.

It seems there is some problem in the statement - JAXBContext.newInstance("com.xxx.xxx.xxx");



 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!