<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                # [已解決]:線程“`main`”`com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException`中的異常:3 個`IllegalAnnotationExceptions`計數 > 原文: [https://howtodoinjava.com/jaxb/solved-exception-in-thread-main-com-sun-xml-internal-bind-v2-runtime-illegalannotationsexception-3-counts-of-illegalannotationexceptions/](https://howtodoinjava.com/jaxb/solved-exception-in-thread-main-com-sun-xml-internal-bind-v2-runtime-illegalannotationsexception-3-counts-of-illegalannotationexceptions/) 當您使用 [**JAXB**](//howtodoinjava.com/category/frameworks/jaxb/ "JAXB tutorials") 將 Java 對象(集合類型)編組為 xml 格式時,會發生此異常。 棧跟蹤如下所示: ```java Exception in thread "main" com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions Class has two properties of the same name "employees" this problem is related to the following location: at public java.util.List com.howtodoinjava.jaxb.examples.list.Employees.getEmployees() at com.howtodoinjava.jaxb.examples.list.Employees this problem is related to the following location: at private java.util.List com.howtodoinjava.jaxb.examples.list.Employees.employees at com.howtodoinjava.jaxb.examples.list.Employees at com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException$Builder.check(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.<init>(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.<init>(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(Unknown Source) ..... more ``` 或者 ```java Exception in thread "main" com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 3 counts of IllegalAnnotationExceptions java.util.Map is an interface, and JAXB can't handle interfaces. this problem is related to the following location: at java.util.Map at private java.util.Map com.howtodoinjava.jaxb.examples.map.EmployeeMap.employeeMap at com.howtodoinjava.jaxb.examples.map.EmployeeMap java.util.Map does not have a no-arg default constructor. this problem is related to the following location: at java.util.Map at private java.util.Map com.howtodoinjava.jaxb.examples.map.EmployeeMap.employeeMap at com.howtodoinjava.jaxb.examples.map.EmployeeMap Class has two properties of the same name "employeeMap" this problem is related to the following location: at public java.util.Map com.howtodoinjava.jaxb.examples.map.EmployeeMap.getEmployeeMap() at com.howtodoinjava.jaxb.examples.map.EmployeeMap this problem is related to the following location: at private java.util.Map com.howtodoinjava.jaxb.examples.map.EmployeeMap.employeeMap at com.howtodoinjava.jaxb.examples.map.EmployeeMap ......more ``` ![Random exceptions](https://img.kancloud.cn/81/c9/81c97e6ebb55a2bdb88e52750e274fe3_300x350.png) 隨機異常 ## 原因 發生上述異常的主要原因是缺少`@XmlAccessType`注解或對`@XmlAccessType`和`@XxmlElement`注解的無效使用。 正確的用法是,一個 Java 字段應只包含一個表示其元數據的有效 JAXB 注解。 默認情況下,JAXB 包含所有公開字段和用于整理的獲取器。 因此,如果您有一個字段及其獲取器,那么它將包含兩次。 這是錯誤,需要通過正確使用注解來解決。 ## 解決方案:使用`@XmlAccessType`注解 **1)`@XmlAccessorType(XmlAccessType.FIELD)`** 如果您使用的是`XmlAccessType.FIELD;`那么只有所有公開字段(非靜態)將被自動包括在內以進行編組。 不會考慮吸氣劑。 因此,如果將消除重復的問題。 例如,在下面的代碼中,將同時包含`employee`和`size`字段。 請注意,“`@XmlElement(name="employee")`”是可選的; 我用它來重命名輸出 xml 中的 xml 節點。 如果刪除它; 不會出現任何編組錯誤或異常。 ```java @XmlRootElement(name = "employees") @XmlAccessorType (XmlAccessType.FIELD) public class Employees { @XmlElement(name="employee") private List<Employee> employees = null; private Integer size; public List<Employee> getEmployees() { return employees; } public void setEmployees(List<Employee> employees) { this.employees = employees; } public Integer getSize() { return size; } public void setSize(Integer size) { this.size = size; } } ``` **2)`@XmlAccessorType(XmlAccessType.NONE)`** 如果使用“`XmlAccessType.NONE`”,則意味著必須在輸出 XML 中注解所有要編組的字段。 剩下的任何字段都不會包含在 JAXB 上下文中。 因此,本質上,`employee`和`size`字段都需要`@XmlElement`注解。 如果這兩個字段中的任何一個都未使用`@XmlElement`注解,則不會將其編組。 ```java @XmlRootElement(name = "employees") @XmlAccessorType (XmlAccessType.NONE) public class Employees { @XmlElement(name="employee") private List<Employee> employees = null; @XmlElement(name="size") private Integer size; public List<Employee> getEmployees() { return employees; } public void setEmployees(List<Employee> employees) { this.employees = employees; } public Integer getSize() { return size; } public void setSize(Integer size) { this.size = size; } } ``` **祝您學習愉快!**
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看