gpt4 book ai didi

java - 无法从类访问父类(super class)

转载 作者:太空宇宙 更新时间:2023-11-04 12:21:09 25 4
gpt4 key购买 nike

我创建了一个简单的 Java 客户端,它根据 XSD 生成的类构建 XML 消息,然后将其感知到 Web 服务。当我从我的工作站测试它时它工作正常,但是当我将类加载到 Oracle 数据库时,我收到以下错误:

Exception in thread "Root Thread" java.lang.IllegalAccessError: cannot access superclass from class
at sun.misc.Unsafe.defineClass(Native Method)
at sun.reflect.ClassDefiner.defineClass(ClassDefiner.java)
at sun.reflect.MethodAccessorGenerator$1.run(MethodAccessorGenerator.java)
at java.security.AccessController.doPrivileged(Native Method)
at sun.reflect.MethodAccessorGenerator.generate(MethodAccessorGenerator.java)
at sun.reflect.MethodAccessorGenerator.generateConstructor(MethodAccessorGenerator.java)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java)
at java.lang.reflect.Constructor.newInstance(Constructor.java)
at java.lang.reflect.Proxy.newInstance(Proxy.java)
at java.lang.reflect.Proxy.newProxyInstance(Proxy.java)
at sun.reflect.annotation.AnnotationParser.annotationForMap(AnnotationParser.java)
at sun.reflect.annotation.AnnotationParser.parseAnnotation2(AnnotationParser.java)
at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java)
at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java)
at java.lang.reflect.Field.declaredAnnotations(Field.java)
at java.lang.reflect.Field.getDeclaredAnnotations(Field.java)
at java.lang.reflect.AccessibleObject.getAnnotations(AccessibleObject.java)
at com.sun.xml.internal.bind.v2.model.annotation.RuntimeInlineAnnotationReader.getAllFieldAnnotations(RuntimeInlineAnnotationReader.java)
at com.sun.xml.internal.bind.v2.model.annotation.RuntimeInlineAnnotationReader.getAllFieldAnnotations(RuntimeInlineAnnotationReader.java)
at com.sun.xml.internal.bind.v2.model.impl.ClassInfoImpl.findFieldProperties(ClassInfoImpl.java)
at com.sun.xml.internal.bind.v2.model.impl.ClassInfoImpl.getProperties(ClassInfoImpl.java)

我认为这可能是由于类位于不同的包中引起的,因此我将所有类移至单个默认包中,但这没有帮助。我还用公共(public)替换了所有 protected /私有(private)字段/类,仍然是同样的问题。

这是我认为失败的地方:

JAXBContext context = JAXBContext.newInstance(PurchaseOrder.class);

感谢任何帮助。谢谢。

采购订单类:

<code>
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "PurchaseOrder", propOrder = {
"purchaseOptions"
})
@XmlRootElement(name = "PurchaseOrder")
public class PurchaseOrder {

@XmlElement(name = "PurchaseOptions")
public ArrayOfPurchaseOptionDescription purchaseOptions;

public ArrayOfPurchaseOptionDescription getPurchaseOptions() {
return purchaseOptions;
}

public void setPurchaseOptions(ArrayOfPurchaseOptionDescription value) {
this.purchaseOptions = value;
}
}

编辑:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "ArrayOfPurchaseOptionDescription", propOrder = {
"purchaseOptionDescription"
})
public class ArrayOfPurchaseOptionDescription {

@XmlElement(name = "PurchaseOptionDescription", nillable = true)
public List<PurchaseOptionDescription> purchaseOptionDescription;

public List<PurchaseOptionDescription> getPurchaseOptionDescription() {
if (purchaseOptionDescription == null) {
purchaseOptionDescription = new ArrayList<PurchaseOptionDescription>();
}
return this.purchaseOptionDescription;
}
}

最佳答案

我认为您应该删除 XML 类型名称,例如:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"purchaseOptions"
})
@XmlRootElement(name = "PurchaseOrder")
public class PurchaseOrder {
...
}

关于java - 无法从类访问父类(super class),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38849333/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com