Results 1 to 10 of 10
  1. #1
    TimHuey is offline Member
    Join Date
    Aug 2009
    Posts
    50
    Rep Power
    0

    Default Jar file has Data file in it...How do I get to it?

    I've tried the following and I keep getting nullpointerexception. I have netbeans compressing the jar file, but that shouldn't matter should it? I think I just have a file path formatting issue:

    Java Code:
    org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(bidit.BiditApp.class).getContext().getResourceMap(BiditView.class);
    
    (I've tried all the methods below seperately and always get nullpointerexecption)
    
    InputStream is = resourceMap.getClassLoader().getResourceAsStream("/resources/Eqps.txt");
    
    InputStream is = resourceMap.getClassLoader().getResourceAsStream("Eqps.txt");
    
    
    InputStream is = resourceMap.getClassLoader().getResourceAsStream("../Eqps.txt");
    
    InputStream is = resourceMap.getClassLoader().getResourceAsStream("../resources/Eqps.txt");

    winRar reports the Bidit.jar structure to look like this:

    Java Code:
    META-INF(folder)
    bidit(folder)
      resources(folder)
         busyicons(folder)
         Eqps.txt(the file I need access to)
    Any ideas on how to get to that file?

  2. #2
    TimHuey is offline Member
    Join Date
    Aug 2009
    Posts
    50
    Rep Power
    0

    Default

    Nevermind. While I was posting this thread and saw the directory structure I decided to try one more thing..

    InputStream is = resourceMap.getClassLoader().getResourceAsStream(" bidit/resources/Eqps.txt");


    BAdabing badaboom it worked. I was under the impression it already new what jar file I was working with and the location in it. The term .getResource() seemed to indicate to me that it was looking in the RESOURCE folder. Guess not!

    You know, sometimes JAVA is absolutely MAGICAL...sometimes not so much.
    Last edited by TimHuey; 09-12-2009 at 07:13 PM.

  3. #3
    TimHuey is offline Member
    Join Date
    Aug 2009
    Posts
    50
    Rep Power
    0

    Default

    REALLY NOT SO MAJICAL!!!

    For cross platform distribution I decided to change the file location to a more generic style.

    InputStream is = resourceMap.getClassLoader().getResourceAsStream(" bidit" + System.getProperty("file.separator") + "resources" + System.getProperty("file.separator") + "Eqps.txt");

    That works fine when I run it without JavaWebStart, but when I use JavaWebStart I get a nullpointerexception:

    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at java.io.Reader.<init>(Unknown Source)
    at java.io.InputStreamReader.<init>(Unknown Source)
    at java.util.Scanner.<init>(Unknown Source)
    at bidit.BiditView.loadLinesMenuItemActionPerformed(B iditView.java:1617)
    at bidit.BiditView.access$2700(BiditView.java:70)
    at bidit.BiditView$24.actionPerformed(BiditView.java: 1294)
    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.AbstractButton.doClick(Unknown Source)
    at javax.swing.plaf.basic.BasicMenuItemUI$Actions.act ionPerformed(Unknown Source)
    at javax.swing.SwingUtilities.notifyAction(Unknown Source)
    at javax.swing.JComponent.processKeyBinding(Unknown Source)
    at javax.swing.JMenuBar.processBindingForKeyStrokeRec ursive(Unknown Source)
    at javax.swing.JMenuBar.processBindingForKeyStrokeRec ursive(Unknown Source)
    at javax.swing.JMenuBar.processBindingForKeyStrokeRec ursive(Unknown Source)
    at javax.swing.JMenuBar.processKeyBinding(Unknown Source)
    at javax.swing.KeyboardManager.fireBinding(Unknown Source)
    at javax.swing.KeyboardManager.fireKeyboardAction(Unk nown Source)
    at javax.swing.JComponent.processKeyBindingsForAllCom ponents(Unknown Source)
    at javax.swing.JComponent.processKeyBindings(Unknown Source)
    at javax.swing.JComponent.processKeyEvent(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.KeyboardFocusManager.redispatchEvent(Unkn own Source)
    at java.awt.DefaultKeyboardFocusManager.dispatchKeyEv ent(Unknown Source)
    at java.awt.DefaultKeyboardFocusManager.preDispatchKe yEvent(Unknown Source)
    at java.awt.DefaultKeyboardFocusManager.typeAheadAsse rtions(Unknown Source)
    at java.awt.DefaultKeyboardFocusManager.dispatchEvent (Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown 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)

  4. #4
    TimHuey is offline Member
    Join Date
    Aug 2009
    Posts
    50
    Rep Power
    0

    Default

    Any idea why it would not work in javawebstart and it will work in the jar?

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

    Default

    My knowledge of java webstart is rudimentary at best, but perhaps this is a security issue. Perhaps not all system properties are available via webstart. Why add this anyway? Why not just use "/" as your file separator as it works?

  6. #6
    TimHuey is offline Member
    Join Date
    Aug 2009
    Posts
    50
    Rep Power
    0

    Default

    I was afraid it might not work on Macs and Linux. I have linux...one way to check huh!

    I don't have a mac but one of my coworkers does. I can ask him to try it. Thanks for saying you don't know either. At least I feel I'm not alone.

  7. #7
    mrmatt1111's Avatar
    mrmatt1111 is offline Senior Member
    Join Date
    Aug 2009
    Location
    San Jose, CA, USA
    Posts
    320
    Rep Power
    5

    Default

    "/" works on windows, linux, and mac. If you really want to be careful about it, you could fail over to "/". In other words if it throws a null exception the first way then try it with "/" on a second pass.
    Last edited by mrmatt1111; 09-13-2009 at 04:38 AM.
    My Hobby Project: LegacyClone

  8. #8
    TimHuey is offline Member
    Join Date
    Aug 2009
    Posts
    50
    Rep Power
    0

    Default

    cool. Thanks mrmatt. I will deploy it and see if I get complaints....by the way. In some of the Java reference material I've been reading I see the word Solaris. Is that the MAC operating system? I know they call it OSX and Leopard and Snow Leopard.

  9. #9
    mrmatt1111's Avatar
    mrmatt1111 is offline Senior Member
    Join Date
    Aug 2009
    Location
    San Jose, CA, USA
    Posts
    320
    Rep Power
    5

    Default

    Solaris... is Sun's server OS.
    My Hobby Project: LegacyClone

  10. #10
    TimHuey is offline Member
    Join Date
    Aug 2009
    Posts
    50
    Rep Power
    0

    Default

    Ok, thanks mrmatt. It's funny, i hardly ever see mention of OSx when there is Java documentation, especially from SUN. Do they not like each other? I've never used a Mac and don't intend on doing so, but one of the major strengths of Java is its ability to work on both windows and mac with very little coding. Seems like something I would broadcast...repeatedly.

Similar Threads

  1. zip a file tp data handler
    By beginer@1234 in forum New To Java
    Replies: 2
    Last Post: 04-27-2009, 06:04 AM
  2. sorting data in txt file
    By cassysumandak in forum New To Java
    Replies: 1
    Last Post: 04-12-2009, 03:02 AM
  3. getting data from a file
    By sugard in forum Advanced Java
    Replies: 2
    Last Post: 03-03-2009, 07:24 AM
  4. Replies: 0
    Last Post: 02-11-2009, 09:53 AM
  5. Data Sorting in a .data file using java
    By stutiger99 in forum New To Java
    Replies: 2
    Last Post: 10-08-2008, 02:52 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
  •