I am a hobby programmer, however I am stuck in this
java application of mine which has to put image from a directory. I have made a new package called finalconnect5.resources and also saved the image which I wanted to put in the GUI. I have tried to use the getSource() code but does not work.
I dont want to use the GUI builder, this has to be done via code,. How can I do it?
Here is what I tried to do
private static final ImageIcon computerIcon = new ImageIcon(GomokuButton.class.getResource("finalconnect5.resources/Computer.png"));
but then got errors and following note.
Exception in thread "main" java.lang.ExceptionInInitializerError
at finalconnect5.Gomoku.createBoard(Gomoku.java:207)
at finalconnect5.Gomoku.<init>(Gomoku.java:51)
at finalconnect5.Gomoku.main(Gomoku.java:222)
Caused by: java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(ImageIcon.java:138)
at finalconnect5.GomokuButton.<clinit>(GomokuButton.java:13)
... 3 more
Java Result: 1
BUILD SUCCESSFUL (total time: 2 seconds)
But for now putting some file from other file (which is physically located in my hard disk), all I am trying to get that image icon in my
applet (using swing and the file formed is a ".jar" file)
Please help me. What should I do?