我在尝试解组 XML 时遇到了一个严重的问题。起初,Member 元素在其“值”属性中仅包含整数(如第一个“EnumType”元素),但是,现在另一个“EnumType”以字符串作为值出现 - 我得到了下面的 NullPointerException。
请注意,Member.java 中的“值”成员在开始时来自类型“int”(当只接受整数作为成员元素的值时)并且它工作正常。仅当我将其更改为 Object 时(我想这是我的问题的根源) - 出现了以下异常。
XML:
<EnumType Name="Genre" UnderlyingType="Edm.Int32">
<Member Name="ACTION" Value="0"/>
<Member Name="COMEDY" Value="1"/>
</EnumType>
<EnumType Name="Rating" UnderlyingType="Edm.String">
<Member Name="RatingA" Value="G"/>
<Member Name="RatingB" Value="PG"/>
</EnumType>
枚举类型.java
@XmlRootElement
public class EnumType {
@XmlElement(name = "Member", namespace = "http://schemas.microsoft.com/ado/2009/11/edm")
private List<Member> members = new LinkedList<Member>();
public List<Member> getMembers() {
return members;
}
}
成员.Java
@XmlRootElement
public class Member {
@XmlAttribute(name = "Name")
private String name;
@XmlAttribute(name = "Value")
private Object value;
public String getName() {
return name;
}
public Object getValue() {
return value;
}
}
解组上述 XML 时,我得到了这个 NullPointerException:
java.lang.NullPointerException at com.sun.xml.internal.bind.v2.runtime.reflect.TransducedAccessor.get(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.property.AttributeProperty.(Unknown来源)在 com.sun.xml.internal.bind.v2.runtime.property.PropertyFactory.create(未知来源)在 com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.(未知来源)在 com。 sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getOrCreate(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getOrCreate(Unknown Source) at com.sun.xml.internal。 bind.v2.runtime.property.ArrayElementProperty.(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.property.ArrayElementNodeProperty.(Unknown Source) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at太阳反射。NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.property。 PropertyFactory.create(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getOrCreate(Unknown Source)在 com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getOrCreate(Unknown Source) 在 com.sun.xml.internal.bind.v2.runtime.property.ArrayElementProperty.(Unknown Source) 在 com.sun。 xml.internal.bind.v2.runtime.property.ArrayElementNodeProperty.(Unknown Source) 在 sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 在 sun.reflect。NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.property。 PropertyFactory.create(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getOrCreate(Unknown Source)在 com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getOrCreate(Unknown Source) 在 com.sun.xml.internal.bind.v2.runtime.property.SingleElementNodeProperty.(Unknown Source) 在 sun.reflect。在 sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) 在 sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)。DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.property.PropertyFactory.create(Unknown Source) at com.sun。 xml.internal.bind.v2.runtime.ClassBeanInfoImpl.(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getOrCreate(Unknown Source) at com.sun.xml.internal.bind.v2 .runtime.JAXBContextImpl.getOrCreate(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.property.SingleElementNodeProperty.(Unknown Source) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect。 java.lang.reflect 中 sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) 中的 NativeConstructorAccessorImpl.newInstance(Unknown Source)。com.sun.xml.internal.bind.v2.runtime.property.PropertyFactory.create(Unknown Source) 的 Constructor.newInstance(Unknown Source) com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.(Unknown来源)在 com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.(未知来源)在 com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getOrCreate(未知来源)。 xml.internal.bind.v2.runtime.JAXBContextImpl.(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(Unknown Source) at com.sun.xml.internal.bind .v2.ContextFactory.createContext(Unknown Source) 在 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 在 sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 在 sun.reflect.DelegatingMethodAccessorImpl。在 java.lang.reflect.Method.invoke(Unknown Source) 在 javax.xml.bind.ContextFinder.newInstance(Unknown Source) 在 javax.xml.bind.ContextFinder.newInstance(Unknown Source) 在 javax.invoke(Unknown Source)。 xml.bind.ContextFinder.find(未知源)在 javax.xml.bind.JAXBContext.newInstance(未知源)在 javax.xml.bind.JAXBContext.newInstance(未知源)在 com.sap.ndb.studio.rdl。 csdlparser.jaxb.JAXBParser.load(JAXBParser.java:26) 在 com.sap.ndb.studio.rdl.datapreview.functions.LoadGRDL.function(LoadGRDL.java:59) 在 org.eclipse.swt.browser.WebSite。在 org.eclipse.swt.internal.ole.win32.COMObject.callback6(COMObject.java:119) 在 org.eclipse.swt.browser.WebSite$7.method6(WebSite.java:129) 调用(WebSite.java:773) ) 在 org.eclipse.swt.internal.win32.OS。DispatchMessageW(Native Method) 在 org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:2546) 在 org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3756) 在 org.eclipse。 ui.internal.Workbench.runEventLoop(Workbench.java:2701) at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2665) at org.eclipse.ui.internal.Workbench.access$4(Workbench.java :2499) 在 org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332) 在 org.eclipse.ui.internal.Workbench$7.run(Workbench.java:679) .internal.Workbench.createAndRunWorkbench(Workbench.java:668) at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149) at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java :124) 在 org.eclipse.equinox.internal.app。EclipseAppHandle.run(EclipseAppHandle.java:196) 在 org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110) 在 org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start( EclipseAppLauncher.java:79) 在 org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:353) 在 org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180) 在 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 org .eclipse.equinox.launcher.Main.invokeFramework(Main.java:629) 在 org.eclipse.equinox.launcher.Main.basicRun(Main.java:584) 在 org.eclipse.equinox.launcher.Main.run(Main.java:1438) 在 org.eclipse.equinox.launcher.Main.main(Main.java:1414)
有任何想法吗?:(