I;m trying to draw an image of a player that i just took off google images. So far nothing is shown when i run my code as i'm making a game. I get the nullpointer exception saying something is wrong with my imageicon and my paintCOmponent method.
THis is the class which has the errors.
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D gc = (Graphics2D) g;
gc.drawImage(getPlayerImg(),row,column, this);
}
public void draw(Graphics2D g2d){
g2d.drawImage(getPlayerImg(),row,column, this);
}
public Image getPlayerImg(){
ImageIcon d = new ImageIcon(this.getClass().getResource("me.jpg"));
return d.getImage();
}
I also have another class which calls the paintComponent method. I thought this class would be the code for making the image appear since it calls an object from the above class.
public void paintComponent(Graphics g){
super.paint(g);
Graphics2D g2d = (Graphics2D) g;
System.out.println("ok");
c.draw(g2d);
System.out.println("painted");
c.setVisible(true);
}
None of the println are printed out on the screen. I don't know what to do :(. The first class has to do with making the map and the second class calls the methods from the first class and makes it. I can't show too much though.