user2277362
user2277362

Reputation: 113

Type of iterator erroneous

I am working on a project in java and I am developing a API for custom components. I am using an interface called DrawHandler to allow the components to draw to a graphics object. To do this every time a component is added I need to add it's DrawHandlers to a list. I am using this code

    public void addComponent(Component c){
         //Add to list of components
         components.add(c);
         //Add all of the components drawHandlers so the component can be drawn
         List<DrawHandler> dhs = c.getDrawHandlers();
         Iterator<DrawHandler> i = dhs.iterator();
         while(i.hasNext()){
            addDrawHandler(i.next());
         }
    }

However when I get an error on this line

 Iterator<DrawHandler> i = dhs.iterator();

and this line

addDrawHandler(i.next())

The error is:

The type of next() is erroneous : where E is a type-variable: E extends Object declared in interface Iterator

If I use this code as sugested

    public void addComponent(Component c){
    //Add to list of components
    components.add(c);
    //Add all of the components drawHandlers so the component can be drawn
    for(DrawHandler handler : c.getDrawHandlers())
        addDrawHandler(handler);
}

I get this error when i compile it :
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous tree type: windows.DrawHandler at windows.MainWin.addComponent(MainWin.java:37) at windows.Main.main(MazeNavigator.java:21) Any sugjestions? What am I doing wrong? thanks for your your help

Upvotes: 0

Views: 1571

Answers (1)

Peter Lawrey
Peter Lawrey

Reputation: 533500

It doesn't explain your error but you may find it compiles fine if you write

for(DrawHandler handler : c.getDrawHandlers())
    addDrawHandler(handler);

Uncompilable source code - Erroneous tree type: windows.DrawHandler

This means you are using an option which allows you to run code which doesn't compile. I suggest you turn this option off and you should see the true cause of your error.

Upvotes: 1

Related Questions