Hi I am new to all of this and am just trying to simple add an Image but I get this error:
Exception in thread "main" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(ImageIcon.java:181)
at bardejov.board.<init>(board.java:26)
at bardejov.Bardejov.<init>(Bardejov.java:17)
at bardejov.Bardejov.main(Bardejov.java:31)
this is my code:
*/ package bardejov; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Image; import javax.swing.ImageIcon; import javax.swing.JPanel; public class board extends JPanel { Image bardejov; public board() { ImageIcon ii = new ImageIcon(this.getClass().getResource("zombiemenu.jpg")); bardejov = ii.getImage(); } public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; g2d.drawImage(bardejov, 10, 10, null); } }
and:
package bardejov; import javax.swing.JFrame; public class Bardejov extends JFrame { public Bardejov() { add(new board()); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(280, 240); setLocationRelativeTo(null); setTitle("Bardejov"); setVisible(true); } /** * @param args the command line arguments */ public static void main(String[] args) { new Bardejov(); }
Any Help would be appreciated.