Results 1 to 6 of 6
  1. #1
    okxx is offline Member
    Join Date
    Apr 2011
    Posts
    3
    Rep Power
    0

    Default can not find icon in .exe made by WinRun4j : java.lang.NullPointerException

    Hi all,

    I have a problem with icons.
    Part of code :

    Java Code:
    	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;
    	}

    Error :
    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
    Last edited by Fubarable; 04-19-2011 at 12:53 PM. Reason: Moderator Edit: code tags added

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default

    I would say to ask the developers/producers of WinRun4j

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Is the icon image path a valid resource path? Is the image present in the Jar file here: "/com/img/cls.jpg" (relative to the current class, that is).

  4. #4
    okxx is offline Member
    Join Date
    Apr 2011
    Posts
    3
    Rep Power
    0

    Default

    yess, icons and path valid, it already works by runnable jar or standart exe(jars out of exe) methods. It fails only when you create exe with fat executable method(jars in exe).

  5. #5
    okxx is offline Member
    Join Date
    Apr 2011
    Posts
    3
    Rep Power
    0

    Default

    Hi all again,

    I ve solved problem with diffrent method. I think this problem about WinRun4j plugin.

    Anyway i found a porgram names Jar2Exe. It creates exe with no problem, no banner, makes a clear exe.

    Thanks all reply

  6. #6
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default

    Quote Originally Posted by okxx View Post
    I think this problem about WinRun4j plugin.
    Didn't I essentially say just that a few posts ago? Did you bother even trying to find a mailing list or forum or some other support/comment/bug link at the "homepage" for that library?

Similar Threads

  1. Replies: 15
    Last Post: 01-13-2011, 06:28 PM
  2. java.lang.NullPointerException
    By Travis in forum AWT / Swing
    Replies: 7
    Last Post: 09-18-2009, 05:49 PM
  3. Replies: 6
    Last Post: 05-27-2009, 01:17 AM
  4. java.lang.NullPointerException
    By vasavi.singh in forum New To Java
    Replies: 1
    Last Post: 02-27-2009, 12:36 PM
  5. java.lang.NullPointerException
    By vasavi.singh in forum New To Java
    Replies: 2
    Last Post: 02-27-2009, 10:11 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •