Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Jaxb:IllegalAnnotationExceptions_Java_Xml_Jaxb - Fatal编程技术网

Java Jaxb:IllegalAnnotationExceptions

Java Jaxb:IllegalAnnotationExceptions,java,xml,jaxb,Java,Xml,Jaxb,我收到以下异常“1次IllegalAnnotationExceptions” 代码: Image image = new Image("url"); StringWriter sw = new StringWriter(); JAXBContext jaxbContext = JAXBContext.newInstance(Image.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); jaxbMarshalle

我收到以下异常“1次
IllegalAnnotationExceptions

代码:

Image image = new Image("url");
StringWriter sw = new StringWriter();
JAXBContext jaxbContext = JAXBContext.newInstance(Image.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
jaxbMarshaller.marshal(image, sw);
类别:

@XmlRootElement(name="ProductImage")
public class Image {

    private String url;

    public Image( String url) {   
        this.url = url;
    }

    @XmlElement(name = "ImageLocation")
    public String getUrl() {
        return this.url;
    }
}
我尝试在字段上设置
@xmlement
注释,并在类上设置AccessorType字段。但我也有同样的例外


我缺少默认构造函数。 公众形象(){ }使用这个类

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;

@XmlRootElement(name="ProductImage")
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(name = "ProductImage", propOrder = {
    "url"
})
public class Image {

    public Image(){}

    private String url;

    public Image( String url) {   
        this.url = url;
    }

    @XmlElement(name = "ImageLocation")
    public String getUrl() {
        return this.url;
    }
}
生成的XML是

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ProductImage>
    <ImageLocation>url</ImageLocation>
</ProductImage>

网址

您得到的异常的堆栈跟踪是什么?