OK, first thing I want to say is: yes, I know there are a number of similar questions on setting a background image in java. However, my situation is a bit different since I got handed a Java project that was started by someone else. I believe that the previous programmer was fairly new to Java GUI programming and I myself am very new to Java GUI programming. Here is what the program will have to do:
- Set up a background image which is a network map of our clients
- Place bandwidth maps to respective clients which is acquired by a url
- Refresh bandwidth graphs every 5 seconds or so
The only thing that the previous programmer did was set up 2 classes, one being the main and one setting up the background image which he had as a monkey from a url
Now, I decided to use MigLayout to organize a grid where I will place the bandwidth images in the correct arrangement. I was having trouble with that so I decided to start a little smaller and change the monkey background to the network map. I added the map jpg to the src library and thought that if I switched URL to File it would work. It didn't and I have been stuck trying to switch things around to get it to work but no cigar.
Below is the code for the setting up a background. This is my first time trying to post code I hope it works:... well I tried several times several ways and googled it several time but posting my code isnt working so I took a screen shot. Nothing is working for me today.
The errors I get are:
Exception in thread "main" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(Unknown Source)
at bwMonBackground.<init>(bwMonBackground.java:21)
at bwMonBackgroundMain.main(bwMonBackgroundMain.java:7)
EDIT: I uncommented out line 18. Here is the main:
public class bwMonBackgroundMain extends bwMonBackground{
public static void main( String[] args )
{
bwMonBackground frame = new bwMonBackground();
migLayout testing = new migLayout();
testing.createLayout();
frame.setVisible(true);
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
}
}
EDIT 2: once i uncommented out line 18 in bwMonBackground.java I get the following errors:
javax.imageio.IIOException: Can't read input file!
at javax.imageio.ImageIO.read(Unknown Source)
at bwMonBackground.<init>(bwMonBackground.java:15)
at bwMonBackgroundMain.main(bwMonBackgroundMain.java:7)
Exception in thread "main" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(Unknown Source)
at bwMonBackground.<init>(bwMonBackground.java:20)
at bwMonBackgroundMain.main(bwMonBackgroundMain.java:7)