Working on Netbeans 8.2 in Java, and Iḿ encountering an error I can't quite make sense of.
I'm trying to check whether a Shape object was clicked on or not, and then remove it from my list of Shape objects (hence the use of iterator). But something is causing a problem that prevents Shape.contain(Point p) from working, giving me this error message:
Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: java.util.Iterator.contains ...
What is the problem here? Shouldn't contains() work like this? What am I missing?
Complete Code:
public DuckHuntPanel() {
setBackground(Color.BLACK);
shapes = new ArrayList<>();
shapes.add(ball);
Timer timer = new Timer(1000 / 60, (ActionListener) this);
timer.start();
addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent me) {
super.mouseClicked(me);
Iterator<Shape> shape = shapes.iterator();
while (shape.hasNext()) {
shape.next();
if (shape.contains(me.getPoint())) { // <- This causes error
if (isDuck) {
score++;
} else {
score--;
shape.remove();
}
isDuck = !isDuck;
}
}
}
});
}