0

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;
                    }
                }
            }
        });
    }
Sagar V
  • 12,158
  • 7
  • 41
  • 68
  • Have you tried this? https://stackoverflow.com/questions/4386076/uncompilable-source-code-runtimeexception-in-netbeans – anemomylos Aug 11 '17 at 14:00
  • Btw shouldn't be `if (shape.next().contains`? The `Iterator` object don't have the `contains` method, the `Shape` object returned by `shape.next()` has it. In that case you should remove the line 'shape.next();' since you'll move to the next object inside the `if` or modify the entire code accordingly. – anemomylos Aug 11 '17 at 14:06
  • @easyjoin.net I tried, but I'm unable to locate the files, as the location seems to have changed in Netbeans 8.2. Any tips on where to find them? (yes, I'm still new to Netbeans) – Laz0rSquid Aug 11 '17 at 14:09
  • @easyjoin.net OMG, thank you! Now it works. – Laz0rSquid Aug 11 '17 at 14:11
  • Don't add answer in questions. Use the answer field instead to share QA style or if this is a typo, delete this question – Sagar V Aug 11 '17 at 14:18

1 Answers1

0

Should be if (shape.next().contains. The Iterator object don't have the contains method, the Shape object returned by shape.next() has it. In that case you should remove the line shape.next(); since you'll move to the next object inside the if or modify the entire code accordingly.

anemomylos
  • 546
  • 1
  • 6
  • 14