[jdom-interest] cannot convert from com.sun.java.util.collections.List to java.util.List

Keith_MacLaury at notes.rlg.org Keith_MacLaury at notes.rlg.org
Fri Mar 21 14:58:06 PST 2003


I cannot get rid of this message.  I'm using Websphere Application
Developer for Java programming, and I just downloaded beta 8.0.

I tried to start with the simplest JDOM code fragment imaginable (stolen
from various sources):

     SAXBuilder builder = new SAXBuilder(
"org.apache.xerces.parsers.SAXParser", false);

     try
     {
          Document doc = builder.build(new
FileInputStream(configfilename));
          Element root = doc.getRootElement();
          listChildren(root, 0);
     }
     catch (JDOMException e)
     {
          System.out.println(args[0] + " is not well-formed.");
          System.out.println(e.getMessage());
     }
     catch (IOException e)
     {
          System.out.println("Could not check " + args[0]);
          System.out.println(" because " + e.getMessage());
     }

public static void listChildren(Element current, int depth)
{
     printSpaces(depth);
     System.out.println(current.getName());
     List children = current.getChildren();   // <-- here's my problem
statement
     Iterator iterator = children.iterator();
     while (iterator.hasNext())
     {
          Element child = (Element) iterator.next();
          listChildren(child, depth+1);
     }
}

private static void printSpaces(int n)
{
     for (int i = 0; i < n; i++)
     {
          System.out.print(' ');
     }
}

And I can't get past the compile error  "Type mismatch: cannot convert from
com.sun.java.util.collections.List to java.util.List".

I try to leave collections.jar out of my classpath and I get:  "This
compilation unit indirectly references the missing type
com.sun.java.util.collections.List (typically some required class file is
referencing a type outside the classpath)"

Something somewhere seems to think that Element.getChildren returns a
com.sun.java.util.collections.List rather than a java.util.List.

Help!

Keith MacLaury, Newbie




More information about the jdom-interest mailing list