我正在尝试注释一个 java 类以创建一个 JAXB 模式,其中包含一个具有 value 属性的元素。代码如下:
@XmlAttribute(name="value")
public Object getSettingValue() {
return this.settingValue;
}
public void setSettingValue( final Object settingValue ) {
this.settingValue = settingValue;
}
当我尝试生成模式(使用 Eclipse 的非 Moxy 实现)时,我得到了这个空指针异常:
Exception in thread "main" java.lang.NullPointerException
at com.sun.xml.internal.bind.v2.runtime.reflect.TransducedAccessor.get(TransducedAccessor.java:154)
at com.sun.xml.internal.bind.v2.runtime.property.AttributeProperty.<init>(AttributeProperty.java:56)
at com.sun.xml.internal.bind.v2.runtime.property.PropertyFactory.create(PropertyFactory.java:93)
at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.<init>(ClassBeanInfoImpl.java:145)
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getOrCreate(JAXBContextImpl.java:479)
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:305)
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1100)
at com.sun.xml.internal.bind.v2.ContextFactory.createContext(ContextFactory.java:143)
at com.sun.xml.internal.bind.v2.ContextFactory.createContext(ContextFactory.java:110)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:202)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:376)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:574)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:522)
at org.eclipse.jpt.jaxb.core.schemagen.Main.buildJaxbContext(Main.java:95)
at org.eclipse.jpt.jaxb.core.schemagen.Main.generate(Main.java:76)
at org.eclipse.jpt.jaxb.core.schemagen.Main.execute(Main.java:62)
at org.eclipse.jpt.jaxb.core.schemagen.Main.main(Main.java:47)
当我将其设为 @XmlElement 而不是属性时,生成的模式没有问题,因此它必须与此有关。有任何想法吗?