I'm having a NullPointerException
when I compile my code but it works fine in eclipse.
Error log from command prompt:
java.lang.NullPointerException
at sun.awt.image.URLImageSource.getConnection(Unknown Source)
at sun.awt.image.URLImageSource.getDecoder(Unknown Source)
at sun.awt.image.InputStreamImageSource.doFetch(Unknown Source)
at sun.awt.image.ImageFetcher.fetchloop(Unknown Source)
at sun.awt.image.ImageFetcher.run(Unknown Source)
The class getting the images is:
package tileGame;
import java.awt.Toolkit;
import javax.swing.ImageIcon;
public class Image {
public String address1;
public String address2;
public String name;
public String type;
public java.awt.Image image;
public Image(String name){
address1 = System.getProperty("user.dir");
address2 = "/Resources/Images/";
type = "png";
this.name = name;
}
public Image(String name, String type){
address1 = System.getProperty("user.dir");
address2 = "/src/Resources/Images/";
this.type = type;
this.name = name;
}
public Image(String name, String type, String address){
address1 = System.getProperty("user.dir");
this.address2 = address;
this.type = type;
this.name = name;
}
public void loadImage(){
//image = new ImageIcon(address1 + address2 + name + "." + type).getImage();
image = new ImageIcon(Toolkit.getDefaultToolkit().getImage(getClass().getResource(address2 + name + "." + type))).getImage();
System.out.println("Image Loaded '" + name + "' at '" + address2 + name + "." + type + "'");
}
}
There is probably a good reason for this that I can't see as I am fairly new to Java so if anyone could give me some pointers then that would be welcome.
Edit: OK I fixed it just common human error that I wouldn't have spotted on my own. Thanks.