Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/388.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.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 解组“类型不匹配:无法从XmlAccessType转换为AccessType”时出错_Java_Xml_Xsd_Jaxb - Fatal编程技术网

Java 解组“类型不匹配:无法从XmlAccessType转换为AccessType”时出错

Java 解组“类型不匹配:无法从XmlAccessType转换为AccessType”时出错,java,xml,xsd,jaxb,Java,Xml,Xsd,Jaxb,我正在使用Jaxb,解组xml。我正在使用Java1.6。这是通过JWSDP 2.0生成的类。但是我的问题是我无法编译生成的类。我得到一个语法错误,如下所示 类型不匹配:无法从XmlAccessType转换为AccessType 在这方面,有人能帮忙吗?我用下面的演示代码尝试了你问题中的Personinfo类,一切正常。因为您使用的是包含JAXB实现的JavaSE6,所以您需要确保您的类路径上没有任何来自JWSDP2.0的JAXB API 我还建议使用Java SE 6中的XJC实用程序,而不是

我正在使用Jaxb,解组xml。我正在使用Java1.6。这是通过JWSDP 2.0生成的类。但是我的问题是我无法编译生成的类。我得到一个语法错误,如下所示

类型不匹配:无法从XmlAccessType转换为AccessType

在这方面,有人能帮忙吗?

我用下面的演示代码尝试了你问题中的Personinfo类,一切正常。因为您使用的是包含JAXB实现的JavaSE6,所以您需要确保您的类路径上没有任何来自JWSDP2.0的JAXB API

我还建议使用Java SE 6中的XJC实用程序,而不是JWSDP,因为JWSDP非常古老:

演示

input.xml/Output

我用下面的演示代码尝试了你问题中的Personinfo类,一切正常。因为您使用的是包含JAXB实现的JavaSE6,所以您需要确保您的类路径上没有任何来自JWSDP2.0的JAXB API

我还建议使用Java SE 6中的XJC实用程序,而不是JWSDP,因为JWSDP非常古老:

演示

input.xml/Output

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;


@XmlAccessorType(XmlAccessType.FIELD)// here i am getting sytax error
@XmlType(name = "personinfo", propOrder = {
    "firstname",
    "lastname",
    "address"
})
public class Personinfo {

    @XmlElement(required = true)
    protected String firstname;
    @XmlElement(required = true)
    protected String lastname;
    @XmlElement(name = "Address", required = true)
    protected PersonAddress address;
............................
package forum10514244;

import java.io.File;
import javax.xml.bind.*;
import javax.xml.transform.stream.StreamSource;

public class Demo {

    public static void main(String[] args) throws Exception {
        JAXBContext jc = JAXBContext.newInstance(Personinfo.class);

        File xml = new File("src/forum10514244/input.xml");
        Unmarshaller unmarshaller = jc.createUnmarshaller();
        JAXBElement<Personinfo> je = unmarshaller.unmarshal(new StreamSource(xml), Personinfo.class);

        Marshaller marshaller = jc.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        marshaller.marshal(je, System.out);
    }

}
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<root>
    <firstname>Jane</firstname>
    <lastname>Doe</lastname>
    <Address/>
</root>