Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.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 使用Dom解析会产生类型不匹配_Java_Xml_Parsing_Dom_Reflection - Fatal编程技术网

Java 使用Dom解析会产生类型不匹配

Java 使用Dom解析会产生类型不匹配,java,xml,parsing,dom,reflection,Java,Xml,Parsing,Dom,Reflection,给定以下代码,在Eclipse下,我得到一个类型不匹配错误: package xmlInterface; import javax.swing.text.*; import org.w3c.dom.*; import org.w3c.dom.Document; import gameManage.round; import java.io.File; import javax.lang.model.element.Element; import javax.swing.text.Se

给定以下代码,在Eclipse下,我得到一个类型不匹配错误:

package xmlInterface;


import javax.swing.text.*;
import org.w3c.dom.*;
import org.w3c.dom.Document;

import gameManage.round;

import java.io.File;

import javax.lang.model.element.Element;

import javax.swing.text.Segment;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import com.sun.org.apache.bcel.internal.classfile.Method;







        public void writeToXml(round[] games) throws ParserConfigurationException
        {


                       int i;
                // build a doucument by the parser
                       DocumentBuilderFactory document = DocumentBuilderFactory.newInstance();
                       DocumentBuilder docBuilder = document.newDocumentBuilder();

                       Document doc = docBuilder.newDocument();
                       Element rootElement = doc.createElement("GameOut");
...
...
...
}
我在Eclipse中遇到以下错误:

Type mismatch: cannot convert from org.w3c.dom.Element to javax.lang.model.element.Element
有人能解释一下我该如何解决这个问题吗

多谢各位
杰森

我想你弄错了进口货。不是

import javax.lang.model.element.Element;
但是

不要将导入与*like一起使用

org.w3c.dom.*
否则,您可能会得到一些“隐藏”错误,因为您编码的最后一个“元素”导入(javax.lang.model.Element.Element)将隐藏导入org.w3c.dom.*行中包含的org.w3c.dom.Element

org.w3c.dom.*