I want to add image in java swing, I wrote a simple code with out any error in the code(l also tried ("rr.png") instead ("c:\rr.png") but in both situation I got this when l want run it:
Exception in thread "main" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(Unknown Source)
at quize1.uml.<init>(uml.java:14)
at quize1.uml.main(uml.java:20)
Here is my code:
import java.awt.FlowLayout;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class uml extends JFrame {
private ImageIcon image2;
private JLabel Label2;
public uml() {
setLayout(new FlowLayout());
image2 = new ImageIcon(getClass().getResource("c:\\rr.png"));
Label2 = new JLabel( image2);
add (Label2);
}
public static void main(String arg[]) {
uml gui = new uml();
gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
gui.setVisible(true);
gui.setTitle("uml ");
}}