java - com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException : 3 counts of IllegalAnnotationExceptions

标签 java jaxb

当我将 Java 版本从 1.7 更改为 1.6 时,出现以下错误

Error while loading configuration file: 
com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 3 counts of IllegalAnnotationExceptions
weka.core.Instances does not have a no-arg default constructor.
this problem is related to the following location:
    at weka.core.Instances
    at public java.util.ArrayList lpcforsos.baseLearner.DecompositionBasedLearner.getDecomposedDatasets()
    at lpcforsos.baseLearner.DecompositionBasedLearner
    at public lpcforsos.baseLearner.DecompositionBasedLearner lpcforsos.configuration.Configuration.getLearnerEnvironment()
    at lpcforsos.configuration.Configuration
lpcforsos.dataStructure.ExtInstances does not have a no-arg default constructor.
this problem is related to the following location:
    at lpcforsos.dataStructure.ExtInstances
    at public lpcforsos.dataStructure.ExtInstances lpcforsos.baseLearner.DecompositionBasedLearner.getTrainingSet()
    at lpcforsos.baseLearner.DecompositionBasedLearner
    at public lpcforsos.baseLearner.DecompositionBasedLearner lpcforsos.configuration.Configuration.getLearnerEnvironment()
    at lpcforsos.configuration.Configuration
lpcforsos.evaluation.Result does not have a no-arg default constructor.
this problem is related to the following location:
    at lpcforsos.evaluation.Result
    at protected lpcforsos.evaluation.Result lpcforsos.structuredPrediction.StructuredPredictor.results
    at lpcforsos.structuredPrediction.StructuredPredictor
    at lpcforsos.structuredPrediction.PairwiseCoupling
    at public lpcforsos.structuredPrediction.PairwiseCoupling lpcforsos.configuration.Configuration.getPairwiseCoupling()
    at lpcforsos.configuration.Configuration

at com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException$Builder.check(IllegalAnnotationsException.java:91)
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:436)
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:277)
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1100)
at com.sun.xml.internal.bind.v2.ContextFactory.createContext(ContextFactory.java:143)
at com.sun.xml.internal.bind.v2.ContextFactory.createContext(ContextFactory.java:110)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:202)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:376)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:574)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:522)
at lpcforsos.configuration.Configuration.loadConfig(Configuration.java:387)
at lpcforsos.evaluation.Evaluation.main(Evaluation.java:68)

我的XML如下

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<decomposer xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="topicRankingDecomposer">
</decomposer>   
<learnerEnvironment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="wekaBaseLearner">
</learnerEnvironment>
<structuredPredictor xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="wuLingWeng2">
</structuredPredictor>
<essentials>
</essentials>
</configuration>

上述标签中decomposer、learnerEnvironment和structuredPredictor都是抽象类 每个类都有 3 个或更多具体类。 解码 xml 时,相应的具体类对象被分配给抽象类变量。

我没有使用任何注释,当我使用 Java 1.7 时它工作得非常完美。现在,当我尝试使用 JDK 1.6 时,出现上述错误。

public class Configuration {

private Decomposer decomposer;
// Subtypes of Decomposer
private ReinforcementLearningDecomposer reinforcementLearningDecomposer;
private OneAgainstAllDecomposer oneAgainstAllDecomposer;
private TopicRankingDecomposer topicRankingDecomposer;
private PairwiseDecomposer pairwiseDecomposer;

private DecompositionBasedLearner learnerEnvironment;
// Subtypes of BaseLearner
private WekaBaseLearner wekaBaseLearner;
private SeCoBaseLearner seCoBaseLearner;
// Predictor Instance

private StructuredPredictor structuredPredictor;
// Subtypes of Predictor
private PairwiseCoupling pairwiseCoupling;
private WuLingWeng2 wuLingWeng2;
private Voting voting;
private WeightedVoting weightedVoting;

// Other essential fields
private Essentials essentials;
}

最佳答案

您遇到的异常听起来像是导致 JAXB 出现问题的实际问题。以下是其中之一,以下说法属实吗?

lpcforsos.evaluation.Result does not have a no-arg default constructor.
this problem is related to the following location:
    at lpcforsos.evaluation.Result
    at protected lpcforsos.evaluation.Result lpcforsos.structuredPrediction.StructuredPredictor.results
    at lpcforsos.structuredPrediction.StructuredPredictor
    at lpcforsos.structuredPrediction.PairwiseCoupling
    at public lpcforsos.structuredPrediction.PairwiseCoupling lpcforsos.configuration.Configuration.getPairwiseCoupling()
    at lpcforsos.configuration.Configuration

您在 JDK 1.7 中使用的 JAXB impl 可能会延迟处理元数据,而 JDK 1.6 impl 则不会。您是否能够在 JDK 1.7 中解码 lpcforsos.evaluation.Result 的实例,或者您当时是否收到异常?

关于java - com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException : 3 counts of IllegalAnnotationExceptions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20482255/

相关文章:

java - 需要 JAXB 中的一个元素或另一个元素

java - 从 WSDL 文件生成 Java 代码

java - 如何将两个不同的对象添加到一个对象中

java - 使用已定义的根(起始)元素将 DTD 转换为 XSD

java - 试图计算出链表空指针错误的大小

java - Google Chrome 使用 Selenium 进行节流

java - 在 Red Hat 服务器中找不到 JAVA_HOME

java - 将 Java ENUM 转换为 XML

java - 如何通过API获取windchill中的序号

java - 更改 Web 应用程序语言