"agt_back-64.png" is in the same package/folder as this class. I have tried putting it in its own image folder. I have changed "agt_back-64.png" to include some or all of its directories. I have even opened a form editor in eclipse and tried to invoke the setIcon() from the form editor using its file chooser, but no luck.

The thing is, I tried this in NetBeans earlier today and it worked perfectly. I even copy and pasted the exact line of code I used in NetBeans and replaced the file directory, but I still get a null pointer. Does anyone have any possible solutions or diagnosis?

Or maybe someone has an alternative way to import images into Eclipse or something?

Here's the exception I'm getting if it helps:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(Unknown Source)
at s.Clone.getJButton8(Clone.java:1639)
at s.Clone.getJPanel8(Clone.java:1609)
at s.Clone.getJDialog3(Clone.java:1597)
at s.Clone.<init>(Clone.java:1231)
at s.Clone$5.run(Clone.java:1251)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

Re: Images in Eclipse IDE

How did you add the images? Did you use the File->Import feature? If not, try using that.

@Dogstopper, that would make a difference if you jar but not if you run from Eclipse

@OP: Does you .java and .class in the same folder ? Not the default for Eclipse.
Make sur your .png is in the same folder as your .class.
Do a System.out.println(backArrowIcon);
if it does not print "null" it means the read was done correctly, the problem is somewhere else.

Re: Images in Eclipse IDE

How did you add the images? Did you use the File->Import feature? If not, try using that.

@Dogstopper, that would make a difference if you jar but not if you run from Eclipse

@OP: Does you .java and .class in the same folder ? Not the default for Eclipse.
Make sur your .png is in the same folder as your .class.
Do a System.out.println(backArrowIcon);
if it does not print "null" it means the read was done correctly, the problem is somewhere else.

What is your class "s" ? Does it implement cloneable ?

System.out.println(backArrowIcon) returned agt_back-64.png.
No, I do not believe class "s" implements cloneable.

"agt_back-64.png" is in the same package/folder as this class. I have tried putting it in its own image folder. I have changed "agt_back-64.png" to include some or all of its directories. I have even opened a form editor in eclipse and tried to invoke the setIcon() from the form editor using its file chooser, but no luck.

The thing is, I tried this in NetBeans earlier today and it worked perfectly. I even copy and pasted the exact line of code I used in NetBeans and replaced the file directory, but I still get a null pointer. Does anyone have any possible solutions or diagnosis?

Or maybe someone has an alternative way to import images into Eclipse or something?

Here's the exception I'm getting if it helps:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(Unknown Source)
at s.Clone.getJButton8(Clone.java:1639)
at s.Clone.getJPanel8(Clone.java:1609)
at s.Clone.getJDialog3(Clone.java:1597)
at s.Clone.<init>(Clone.java:1231)
at s.Clone$5.run(Clone.java:1251)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

I had the same problem with ImageIcon, I couldn't add an png image in my menubar.
Here's what i did to solve the problem..
create a new folder named 'res' along with 'src' and 'bin' folders in your project folder..
copy and paste the image file in the 'res' folder..
go to eclipse and refresh your project..
After refresh, you should be able to see the folder and the image file in the package explorer..
run the code and test it..