tmn
tmn

Reputation: 11559

JAR Export throws Null pointer exception on getClass().getResource()

I cloned this project from GitHub in Eclipse (requires Maven to set up quickly). I may or may not tweak it, but I want to export it into a JAR file. https://github.com/eugener/oxbow

When I run the test main method in in src/test/java/org/oxbow/swingbits/dialog/table/filter/TableFilterTest.java it runs fine.

But when I export the project into a JAR file and use it on my own JTables, I get a null pointer exception. It apparently lost track of the image icons and cannot import them.

java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(Unknown Source)
at org.oxbow.swingbits.table.filter.TableFilterColumnPopup.buildContent(TableFilterColumnPopup.java:173)
at org.oxbow.swingbits.popup.PopupWindow$1.popupMenuWillBecomeVisible(PopupWindow.java:67)
at javax.swing.JPopupMenu.firePopupMenuWillBecomeVisible(Unknown Source)
at javax.swing.JPopupMenu.setVisible(Unknown Source)
at javax.swing.JPopupMenu.show(Unknown Source)
at org.oxbow.swingbits.popup.PopupWindow.show(PopupWindow.java:110)
at org.oxbow.swingbits.table.filter.TableFilterColumnPopup.showFilterPopup(TableFilterColumnPopup.java:278)
at org.oxbow.swingbits.table.filter.TableFilterColumnPopup.mouseReleased(TableFilterColumnPopup.java:237)
at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)

I don't know much about Maven other than it organizes a project's setup. Can someone please tell me if I'm missing a step?

Upvotes: 0

Views: 811

Answers (1)

tmn
tmn

Reputation: 11559

I figured out the issue, although it did require modifying the code. The resource path had to be absolute in the context of a JAR file

new ImageIcon(getClass().getResource("/resources/org/oxbow/swingbits/table/filter/funnel_delete.png")))

instead of

new ImageIcon(getClass().getResource("funnel_delete.png")))

Upvotes: 0

Related Questions