1

I have an error when unmarshaling XML to Java object with JAXB:

java.lang.NullPointerException
    at com.sun.xml.internal.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl$1.parse(RuntimeBuiltinLeafInfoImpl.java:188)
    at com.sun.xml.internal.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl$1.parse(RuntimeBuiltinLeafInfoImpl.java:186)
    at com.sun.xml.internal.bind.v2.runtime.reflect.TransducedAccessor$CompositeTransducedAccessorImpl.parse(TransducedAccessor.java:230)
    at com.sun.xml.internal.bind.v2.runtime.unmarshaller.LeafPropertyLoader.text(LeafPropertyLoader.java:50)
    at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext.text(UnmarshallingContext.java:483)
    at com.sun.xml.internal.bind.v2.runtime.unmarshaller.InterningXmlVisitor.text(InterningXmlVisitor.java:78)
    at com.sun.xml.internal.bind.v2.runtime.unmarshaller.StAXEventConnector.handleCharacters(StAXEventConnector.java:173)
    at com.sun.xml.internal.bind.v2.runtime.unmarshaller.StAXEventConnector.bridge(StAXEventConnector.java:127)
    at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:392)
    at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:368)

How can I find the cause?

some more details:

part of the xml that I am trying to parse is:

<member_resources>
                    <__field_location__>
                            <directive>
                                    sun-sat
                            </directive>
                            <file>
                                    null
                            </file>
                            <line>
                                    0
                            </line>
                    </__field_location__>
                    <sun-sat>
                            00:00-24:00 tester2
                    </sun-sat>
                    <__field_location__>
                            <directive>
                                    isLine
                            </directive>
                            <file>
                                    null
                            </file>
                            <line>
                                    0
                            </line>
                    </__field_location__>
                    <isLine>
                            true
                    </isLine>
            </member_resources>

when stopping at the event that caused this I get:

next event <__field_location__>
next event <directive>
next event sun-sat
next event <file>
next event null
2
  • What IDE are you using? if it's Eclipse or Netbeans you can just use their debuggers. Commented Feb 27, 2012 at 14:05
  • found the problem: I am using my own xml events for unmarshal. the code new CharactersImpl(key) will cause this exception if key is null. Commented Feb 27, 2012 at 14:19

3 Answers 3

3

Add an exception breakpoint for NullPointerException. When it's hit, explore a few levels higher in the call stack to find out the state of the local variables, you'll probably get a clue as to what is null.

Sign up to request clarification or add additional context in comments.

Comments

3

A good approach is using source of JAXB(its implementation) and a IDE for debugging.

Comments

1

Well, a starting point could be setting a breakpoint at the call to the unmarshaler and check exactly which arguments it is being passed.

First thing I'd check is that what you're passing is actually xml, and that it is both well-formed and valid.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.