Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 12 of 12

Thread: AWT Desktop Open

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    7
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default AWT Desktop Open

    I'm attempting to open a pdf help file on button click. However I get the "File not found" error on button click. 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!

    		/**
    		 * 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.IllegalArgumentException: The file: C:\Documents%20and%20Settings\stnorris\My%20Docume nts\Code\HotDocsTreeBuilder\bin\si\documentation\H ELP%20STUFF.pdf doesn't exist.
    at java.awt.Desktop.checkFileValidation(Unknown Source)
    at java.awt.Desktop.open(Unknown Source)
    at si.gui.GUI$1helpDocListener.actionPerformed(GUI.ja va:981)
    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
    Member
    Join Date
    Mar 2011
    Posts
    84
    My Mood
    Daring
    Thanks
    17
    Thanked 1 Time in 1 Post

    Default Re: AWT Desktop Open

    use text file instead of .pdf

  3. #3
    Junior Member
    Join Date
    Oct 2011
    Posts
    7
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: AWT Desktop Open

    I'd really like to have a PDF open instead of a text. How would I go about making that work?

  4. #4
    Forum VIP
    Join Date
    Oct 2010
    Posts
    275
    My Mood
    Cool
    Thanks
    32
    Thanked 54 Times in 47 Posts
    Blog Entries
    2

    Default Re: AWT Desktop Open

    Instead of the file being at "HELP DESK.pdf"
    make it say
    HELP\ DESK.pdf

    That will fix the problem,and it will open the correct file located at
    HELP DESK.pdf

  5. #5
    Junior Member
    Join Date
    Oct 2011
    Posts
    7
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: AWT Desktop Open

    Thanks Tjstretch. Now I"m getting a new error on the same line, null pointer reference. 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. Stack trace below (Also Tjstretch, what was the reasoning behind that backslash? Why did that work?)

    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)

  6. #6
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: AWT Desktop Open

    This thread has been cross posted here:


    http://www.java-forums.org/awt-swing/50178-awt-desktop-open.html

    Although cross posting is allowed, for everyone's benefit, please read:

    Java Programming Forums Cross Posting Rules

    The Problems With Cross Posting


  7. #7
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: AWT Desktop Open

    What is null on that line? Split up all those calls into individual method calls, assigning references to pinpoint which method is returning null.

  8. #8
    Junior Member
    Join Date
    Oct 2011
    Posts
    7
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: AWT Desktop Open

    the filename is coming back null from ClassLoader.getSystemResource. I modified the code to the below to pinpoint the exact null reference.

  9. #9
    Junior Member
    Join Date
    Oct 2011
    Posts
    7
    Thanks
    0
    Thanked 1 Time in 1 Post

    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.

  10. #10
    Member
    Join Date
    Jun 2011
    Location
    Rhode Island
    Posts
    69
    My Mood
    Bored
    Thanks
    11
    Thanked 7 Times in 6 Posts

    Default Re: AWT Desktop Open

    answered my own question but it was interesting that it must be Windows machine version only. I dont think the Linux side has that.
    Last edited by william; October 24th, 2011 at 01:47 PM.

  11. #11
    Junior Member
    Join Date
    Oct 2011
    Posts
    7
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: AWT Desktop Open

    Strange, there's no %20 space replace in Linux? Well, the replace still shouldn't cause an issue so it's still cross-platform at least.

  12. The Following User Says Thank You to StevenTNorris For This Useful Post:

    william (October 24th, 2011)

  13. #12
    Member
    Join Date
    Jun 2011
    Location
    Rhode Island
    Posts
    69
    My Mood
    Bored
    Thanks
    11
    Thanked 7 Times in 6 Posts

    Default Re: AWT Desktop Open

    I am not sure I been in working out of Windows too long, currently if i remember that you are not allowed spaces for path names in Linux. Then again I should just fire up the VM ware for CentOS and test it.

    Retract that "name\ last" works.

    interesting thanks Steven.

Similar Threads

  1. NetBeans Desktop Application in Java
    By knightmetal in forum Java IDEs
    Replies: 5
    Last Post: November 9th, 2011, 06:47 AM
  2. Netbean Desktop Application Help!!
    By flyto9 in forum Java Theory & Questions
    Replies: 2
    Last Post: June 30th, 2011, 05:52 PM
  3. Remote Desktop Application
    By Drango in forum Java ME (Mobile Edition)
    Replies: 3
    Last Post: January 24th, 2011, 08:01 AM
  4. SQLite and Desktop Application
    By urosz in forum JDBC & Databases
    Replies: 12
    Last Post: November 2nd, 2009, 03:50 AM
  5. Desktop Database Application
    By TCoomer in forum JDBC & Databases
    Replies: 2
    Last Post: June 4th, 2009, 03:51 PM