Results 1 to 3 of 3
  1. #1
    StevenTNorris is offline Member
    Join Date
    Oct 2011
    Posts
    9
    Rep Power
    0

    Default AWT Desktop Open

    I'm attempting to open a pdf help file on button click. However I get a null pointer exception on button click. I'm not sure where this would be coming from, unless somehow the Desktop is returning null. I haven't used the AWT Desktop before, so I'm not familiar with how it works very well.
    None of the JOptionPanes show, leading me to below it isn't even catching the error. Error line is the Desktop.getDesktop() line. Both the listener and the error code are below. The package structure leading to the file I'm accessing is si/documentation/HELP STUFF.pdf. Thanks in advance!

    Java Code:
    /**
    * Opens help documentation
     * 
     * @author stnorris
     */
    class helpDocListener implements ActionListener{
     	private GUI gui;
     		public helpDocListener(GUI gui){
    			this.gui = gui;
    		}
     
    		@Override
    		public void actionPerformed(ActionEvent arg0) {
    			try {
    				if(Desktop.isDesktopSupported()){
    					Desktop.getDesktop().open(new File(ClassLoader.getSystemResource("si/documentation/HELP STUFF.pdf").getFile()));
    			}
    				else{
    					JOptionPane.showMessageDialog(gui, "Could not load documentation.", "Error", JOptionPane.ERROR_MESSAGE);
    				}
    			} catch (IOException e) {
    				JOptionPane.showMessageDialog(gui, "Could not load documentation.", "Error", JOptionPane.ERROR_MESSAGE);
    				e.printStackTrace();
    			}
    		}
     
    	}
    STACK TRACE

    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at si.gui.GUI$1helpDocListener.actionPerformed(GUI.ja va:1026)
    at javax.swing.AbstractButton.fireActionPerformed(Unk nown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed (Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed (Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.AbstractButton.doClick(Unknown Source)
    at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unk nown Source)
    at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mou seReleased(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.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.doIntersectio nPrivilege(Unknown Source)
    at java.security.AccessControlContext$1.doIntersectio nPrivilege(Unknown Source)
    at java.awt.EventQueue$2.run(Unknown Source)
    at java.awt.EventQueue$2.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectio nPrivilege(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)

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default Re: AWT Desktop Open

    Cross posted at AWT Desktop Open

  3. #3
    StevenTNorris is offline Member
    Join Date
    Oct 2011
    Posts
    9
    Rep Power
    0

    Default Re: AWT Desktop Open

    Solved it. I was so used to seeing special character code I didn't notice it at first. The ClassLoader.getSystemResource(path).getFile() was replacing all spaces with %20. I'm assuming this is a URL property I didn't know about. So running filename = filename.replace("%20"," ") fixed the path, and thus found the file.

Similar Threads

  1. Replies: 4
    Last Post: 02-07-2011, 08:43 AM
  2. Open an RDP file with Remote Desktop Connection
    By MisterAndy in forum New To Java
    Replies: 0
    Last Post: 12-04-2009, 08:24 PM
  3. Desktop app on an off-focus desktop
    By thommy_lobo in forum Advanced Java
    Replies: 0
    Last Post: 11-09-2009, 06:56 AM
  4. Different Files Open in File -> Open Workspace
    By mgm2010 in forum JCreator
    Replies: 0
    Last Post: 04-11-2009, 02:14 PM
  5. Open source Email client (Desktop Based)
    By success21061985 in forum Advanced Java
    Replies: 1
    Last Post: 01-18-2009, 07:00 PM

Posting Permissions

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