while using JFrame
, I tried setting the icon image with the following code
ImageIcon image = new ImageIcon("C:\\barney.jpg");
frame.setIconImage(image.getImage());
It works as expected, but when I set the "C:\\barney.jpg"
as aString
variable
String var = "C:\\barney.jpg";
ImageIcon image = new ImageIcon(var);
frame.setIconImage(image.getImage());
The compiler displays Exception in thread "main" java.lang.Error: Unresolved compilation problem
Another point of confusion is why the line in the error
code refer to the
public static void main(String[] args)
line instead of
String var = "C:\\barney.jpg";
which actually causes the error?