Hi all,
I have a problem with icons.
Part of code :
Code:
Error :private JButton getJButton() { if (jButton == null) { jButton = new JButton(); jButton.setPreferredSize(new Dimension(16, 16)); jButton.setFont(new Font("Dialog", Font.BOLD, 8)); jButton.setIcon(new ImageIcon(getClass().getResource("/com/img/cls.jpg"))); //---> This part fails jButton.setHorizontalAlignment(SwingConstants.CENTER); jButton.setHorizontalTextPosition(SwingConstants.CENTER); jButton.setText(""); jButton.setOpaque(true); jButton.setVisible(false); jButton.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseExited(java.awt.event.MouseEvent e) { jButton.setVisible(false); } public void mouseEntered(java.awt.event.MouseEvent e) { jButton.setVisible(true); } }); } return jButton; }
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(Unknown Source)
at com.FormMain.addtoJTabbedPane(FormMain.java:169)
at com.FormMain.treeSelectionHandler(FormMain.java:12 5)
at com.FormMain.access$0(FormMain.java:102)
at com.FormMain$1.valueChanged(FormMain.java:67)
at javax.swing.JTree.fireValueChanged(Unknown Source)
at javax.swing.JTree$TreeSelectionRedirector.valueCha nged(Unknown Source)
at javax.swing.tree.DefaultTreeSelectionModel.fireVal ueChanged(Unknown Source)
at javax.swing.tree.DefaultTreeSelectionModel.notifyP athChange(Unknown Source)
at javax.swing.tree.DefaultTreeSelectionModel.setSele ctionPaths(UnknownSource)
at javax.swing.tree.DefaultTreeSelectionModel.setSele ctionPath(Unknown Source)
at javax.swing.JTree.setSelectionPath(Unknown Source)
at javax.swing.plaf.basic.BasicTreeUI.selectPathForEv ent(Unknown Source)
at javax.swing.plaf.basic.BasicTreeUI$Handler.handleS election(Unknown Source)
at javax.swing.plaf.basic.BasicTreeUI$Handler.mousePr essed(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent( Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(U nknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unkno wn Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilter s(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(U nknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Tool : Eclipse
Source Folder : src
Package : com.img
When i run or debug this code from eclipse it works, no problem.
When i make runnable jar with this code, jar works, no problem.
When i make .exe with this code using WinRun4j with export type= Standart option(jars are out of .exe, in a folder), .exe works, no problem.
But when i make .exe with this code using WinRun4j and export type= Fat Executable option(jars and all files in .exe)it fails, can not find icons and .jrxml files.
Icons are in com.img package in src source folder, but getClass().getResource("/com/img/cls.jpg") returns null??
Whats the wrong or what can i do to solve this, anybody help ?
okxx