Can anyone tell me the syntax to use Color variable in if else statement. I am getting the error Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: java.awt.Color at this line.
You are getting that error message because you didn't check the red marks on Eclipse before compiling. Go back to the source code and hold your mouse over the red mark and see what the error in the little dropdown is.
Joined: Oct 18, 2013
It is showing that cannot find awt class in java package but i think that there is problem with my syntax.
Sarah Qazi wrote:It is showing that cannot find awt class in java package but i think that there is problem with my syntax.
Yes, perhaps you meant
P.S You should use the equals method when comparing non primitives.
Joined: Oct 13, 2005
If you had sorted out that import you would have got rid of the compiler error: import java.awt.Color; not import java.Color; If you had clicked on the red mark it would probably have suggested that change.
It would not have pointed out the logic error of using == which Piet Souris has already told you about. There are more details in the Color class.
It was E. Armitage who pointed to the use of the equals-method, not me.
My stupid reaction was that the Color class doesn't override the 'equals'method, so the easiest thing
would be to use the Color.getRGB() method. But, when looking at the Color API, to my shame
I noticed my blunder. I tried to delete my respons, but as I said, I couldn't. So, never too old to blunder,
So, to clarify: after getting the import correct, Sarah should use: