Parsing using Dom creates type mismatch

Given the following code, in Eclipse I get a type mismatch error:

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");
...
...
...
}

The following error appears in Eclipse:

Type mismatch: cannot convert from org.w3c.dom.Element to javax.lang.model.element.Element

Can someone explain how I can fix this?

Thank. Jason

+3
source share
1 answer

I think you are mistaken in import. Not

import javax.lang.model.element.Element;

but

import org.w3c.dom.Element;

Do not use import with * as

org.w3c.dom.*

otherwise, you will most likely get some "hiding" error, since the last "element" you imported that you encoded (javax.lang.model.element.Element) will hide the included org.w3c.dom.Element in the import line org.w3c.dom. *.

+2
source

All Articles