Java 使用Dom解析会产生类型不匹配
给定以下代码,在Eclipse下,我得到一个类型不匹配错误: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
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.*