badperson
June 27th, 2009, 07:26 PM
I'm trying to load an image to a Panel with the following code:
private Image image;
public LaunchScreenPanel(){
URL url = this.getClass().getResource("lib/images/gui-image.jpg");
if(url==null){
System.err.println("URL is null: ");
System.err.println(this.getClass());
System.err.println("dir: " + System.getProperty("user.dir"));
}
image = Toolkit.getDefaultToolkit().getImage(url);
}
I'm getting this output:
URL is null:
class com.jasonwardenburg.goalapp.gui.LaunchScreenPanel
dir: /media/files/code/java/Workspaces/GoalApplication
Uncaught error fetching image:
java.lang.NullPointerException
at sun.awt.image.URLImageSource.getConnection(URLImag eSource.java:115)
at sun.awt.image.URLImageSource.getDecoder(URLImageSo urce.java:125)
at sun.awt.image.InputStreamImageSource.doFetch(Input StreamImageSource.java:258)
at sun.awt.image.ImageFetcher.fetchloop(ImageFetcher. java:189)
at sun.awt.image.ImageFetcher.run(ImageFetcher.java:1 53)\
the URL object looks like it's null...I looked around on the internet and found examples like the above...anyone know how to fix this?
The code works when I have the file loaded as a File object within eclipse. But when I run the code as a jar or through a bash file, it can't find the image (when loaded as a file instead of getResource());
thanks,
bp
private Image image;
public LaunchScreenPanel(){
URL url = this.getClass().getResource("lib/images/gui-image.jpg");
if(url==null){
System.err.println("URL is null: ");
System.err.println(this.getClass());
System.err.println("dir: " + System.getProperty("user.dir"));
}
image = Toolkit.getDefaultToolkit().getImage(url);
}
I'm getting this output:
URL is null:
class com.jasonwardenburg.goalapp.gui.LaunchScreenPanel
dir: /media/files/code/java/Workspaces/GoalApplication
Uncaught error fetching image:
java.lang.NullPointerException
at sun.awt.image.URLImageSource.getConnection(URLImag eSource.java:115)
at sun.awt.image.URLImageSource.getDecoder(URLImageSo urce.java:125)
at sun.awt.image.InputStreamImageSource.doFetch(Input StreamImageSource.java:258)
at sun.awt.image.ImageFetcher.fetchloop(ImageFetcher. java:189)
at sun.awt.image.ImageFetcher.run(ImageFetcher.java:1 53)\
the URL object looks like it's null...I looked around on the internet and found examples like the above...anyone know how to fix this?
The code works when I have the file loaded as a File object within eclipse. But when I run the code as a jar or through a bash file, it can't find the image (when loaded as a file instead of getResource());
thanks,
bp