2012-02-27 54 views
1

我解编时XML和Java对象与JAXB有一个错误:如何调试这个NullPointerException异常

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) 

我怎样才能找到原因?

一些更多的细节:我试图解析XML的

部分是:

<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> 

在引起该事件停止时,我得到:

next event <__field_location__> 
next event <directive> 
next event sun-sat 
next event <file> 
next event null 
+0

你在用什么IDE?如果它是Eclipse或Netbeans,你可以使用它们的调试器。 – talnicolas 2012-02-27 14:05:15

+0

请张贴一些代码。 – 2012-02-27 14:05:38

+0

发现问题: 我正在使用我自己的xml事件解组。 'new CharactersImpl(key)'的代码将导致这个异常,如果key是'null'的话。 – oshai 2012-02-27 14:19:17

回答

3

NullPointerException添加异常断点。当它被击中时,探索调用堆栈中较高的几个级别来查找局部变量的状态,您可能会得到关于什么是空的线索。

1

好,一个起点可能是在调用解组器的时候设置一个断点,然后检查它正在传递的参数。

我会检查的第一件事是,你传递的实际上是xml,它是格式良好和有效的。

3

一个好方法是使用JAXB(它的实现)的源代码和一个IDE进行调试。