I am developing a small desktop application in Java. I came across a point where i need to read data from XML file, for this i am using Dom4j library. While coding i am facing the following error could anyone guide me in resolving this error:
public void FromXML(String sXMLFileURI)
{//Reads the XML File and Stroe Data in Calling Object
Document document = getDocument( sXMLFileURI );
String xPath = "myXpath";
List<Node> nodes = document.selectNodes( xPath );//This line gives the followiing error:
//error "incompatible types
//required: java.util.List<org.dom4j.Node>
//found: java.util.List<capture#1 of ? extends org.dom4j.Node>"
for (Node node : nodes)
{
//some processing here
}
}
Since the method signature is
your variable
nodesshould be of typeList<? extends Node>, and not of typeList<Node>.A
List<Node>accepts anyNodeinstance as element. Whereas aList<? extends Node>is aList<Node>, or aList<Element>, or aList<Attribute>, or a list of some other subclass ofNode. You just don't know which one.