Laurel Laurel - 5 months ago 8
Java Question

Netbeans shows an error, but the code runs

In one of my Java projects, in Netbeans, I have this "error". It doesn't affect my ability to compile and run my program, and I have no clue why it's there. I already asked some other people and it's baffling everyone.

I made a "minimal" example by removing some code (it could be more minimal, but this isn't code golf):

package cashregister;
public class CashRegister {

public static void main(String[] args) {


But the red stop sign error persists:

Seriously, WTF?

I haven't run this minimal code version, but it should run. Obviously. I suspect this may be an issue with Netbeans. There are questions that run into a similar issue, but not in Java.

The hover text says:

cannot find symbol
symbol: variable ImageIO
location: class CashRegister

variable url may not have been initialized
(Alt-Enter shows hints)

Cannot find symbol indeed. This error started appearing when I copy and pasted in some code (found elsewhere on SO). I can link there if necessary. Note that the copied code actually used
and a variable named

Why is Netbeans showing an error here? How do I fix this?


I did a "clean and build", but the error persisted.

I clicked the x and closed the file, and the error was gone when I open it again. So problem solved (for now).

I assume that restarting would have had the same effect.

(I'm going to leave the question in case anyone else has a similar issue.)

I would assume that it was a cache issue. If anyone has a better explanation, feel free to post your own answer.