• Post Reply Bookmark Topic Watch Topic
  • New Topic

stoppage in JAR runnable file  RSS feed

 
Chris Crawford
Ranch Hand
Posts: 116
1
Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
{When I first submitted this message, the website appears to have hung up on me, so I'm re-submitting it. Apologies if it appears twice. }

My program is now up to about 1700 lines, and it works perfectly inside the Eclipse debugger. However, when I export it to a runnable JAR file and run that JAR file, it freezes. I have spent four days beating my head against the wall trying to fix it. The only information I get from the Console is "Mac OS error -67062", which I cannot find described anywhere on the web. Here is the critical code:



All those lines "myFrame.setTitle("something or other")" are a quick and dirty way to spit out error messages.

My interpretation is that the XML file is not fully loaded when I attempt to start using the data in line 20, which is why the program never gets to line 23.

So is this really a problem with concurrent execution? The one-second delay in line 6 should have given the program plenty of time to load the file (it's only a few hundred lines long).

I'm running on an iMac with OS 10.12.4
 
Stephan van Hulst
Saloon Keeper
Posts: 7974
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hard to say without knowing what encounters is, and what the loadEncounters() method does.
 
Chris Crawford
Ranch Hand
Posts: 116
1
Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Encounter is a conventional data structure; the method loadEncounters() is a standard XML reading routine. I've been using this data structure and this loading routine for months with no problems. Remember, the distinction is between a program that works perfectly while inside the Eclipse environment, then locks up when run as a runnable JAR application. The data structure "encounters" is an ArrayList whose elements are of class Encounter. Here's the basic data structure declaration for class Encounter:



And here is the data structure for the included class Option:



and here is the data structure for the included class Reaction:



As you can see, it's straightforward stuff and should not be the source of the problem.
 
Stephan van Hulst
Saloon Keeper
Posts: 7974
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If encounters really is just an ArrayList, then the line you indicated can not be the cause of your troubles. The only thing I can think of is that you call setTitle() from a thread other than the Event Dispatch Thread.

Are you using Swing or AWT?
 
Stephan van Hulst
Saloon Keeper
Posts: 7974
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I recommend you post an SSCCE. Writing one will often help you identify the cause by yourself, and if it doesn't, it will make it easier for us to assist you.
 
Chris Crawford
Ranch Hand
Posts: 116
1
Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I am using Swing. I'll change all those calls to setTitle() to dumps to the console to see if I can't find out anything. I'll also do a proper dump of the stack trace. Then I'll get back with the results.

Thanks much!
 
Chris Crawford
Ranch Hand
Posts: 116
1
Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I converted the messages to the console, and got nowhere. So now I have begun working on a SSCCE. I'll report back when I've gotten it right.
 
Dave Tolls
Ranch Foreman
Posts: 3056
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this line:

being run on the EDT?
That is, is it in a part of the code that sets up your GUI (via an invokeLater call)?
If so then remove it.
You do not want to be sleeping the EDT (that is the thread that Swing uses to control events and changes to the display).

I doubt that's the issue, but you really don't want that line in there.

Next, stick lots of debugging code in there (printlns are the simplest), including in that loadEncounters() method (which you still haven't shown us).

Until you find out where it's sticking, you won't get anywhere.
 
Chris Crawford
Ranch Hand
Posts: 116
1
Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I deleted the system timer calls. I put some System.out.println() calls into the code, but when it's running in standalone mode, I didn't see any output in the Macintosh Console program. Apparently System.out.println() sends output ONLY to the Eclipse console, not the operating system console. Perhaps I misunderstand your meaning. I built a SSCCE, but had problems with it, so I'm starting over and building it a small step at a time. Will report back with results.
 
Dave Tolls
Ranch Foreman
Posts: 3056
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you executing the jar file?
If it's double clicking then can you try running it from the command line?
 
Chris Crawford
Ranch Hand
Posts: 116
1
Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I cannot imagine what advantage could be obtained by launching from the terminal. I have been using Macs for 33 years now, and I have launched every single program with double-clicking, and I have never had a single problem arising from double-clicking. Not once.
I'm dedicating my time to building the SSCCE.
 
Dave Tolls
Ranch Foreman
Posts: 3056
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will at least see the output from the println calls, which will help you figure out where it gets stuck.
 
Chris Crawford
Ranch Hand
Posts: 116
1
Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, I have gotten a decent SSCCE for your perusal. Here is the code:



Here is a short version of the XML file that it reads:



This code runs fine inside Eclipse. When I export a runnable JAR file and execute that file, it never reaches the line
myFrame.setTitle("completed initialization");

I believe that this is because the program hangs on the line just before it:
theEncounter = encounters.get(0);

I interpret this to mean that the ArrayList encounters has no members, because the loadEncounters method has not been executed.

I need some way to tell Java "Dammit, execute the code in the order I put it in!!!"
 
Stephan van Hulst
Saloon Keeper
Posts: 7974
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, that's impossible. ArrayList never blocks. It may throw an exception but it will never cause your application to hang.

I found your issue. You're trying to load application resources, but instead of using Class.getResourceAsStream(), you're using FileInputStream. Resources are NOT files. The application throws an exception that it can't find the file, but you silently discard the exception and the main thread finishes.

  • Use Class.getResourceAsStream() if the file you're referencing is part of your application.
  • Use Paths.get() and Files.newBufferedReader() or Files.newInputStream() if the file you're referencing is part of the user's file system.
  • NEVER silently discard exceptions.
  • NEVER log to console. The console is unavailable when running javaw, which is what double-clicking JARs does.
  •  
    Stephan van Hulst
    Saloon Keeper
    Posts: 7974
    143
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Have a cow for a good example of an SSCCE!
     
    Chris Crawford
    Ranch Hand
    Posts: 116
    1
    Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Wow! These are completely new concepts to me. I never took any courses in computers; I am completely self-taught, and I got started when the only way to have a computer required lots of soldering, and when entering code in hexadecimal rather than binary was the bee's knees. I feel like a horse-and-buggy driver trying to pilot an F-16.

    I am confused about the difference between a resource and a file. I thought that a resource was something embedded inside the "runnable JAR file". But the runnable JAR file that is built when I export the full program (not the SSCCE) is smaller than the XML file that is read. I thought that I have been loading an external file; that's why I have a JFileChooser in the code. Moreover, the final product must able to select different versions of the XML file, so I think that I want to use an external file rather than an embedded resource.

    Late last night I realized that the problem might arise from the fact that I am loading the XML file BEFORE setting up all the JPanels, JButtons, etc, that go into the JFrame. "Doh!" I said to myself. "What if I build the user interface FIRST, and THEN populate it with the data?"

    Please stop laughing.

    Anyway, that's what I'm working on now.
     
    Stephan van Hulst
    Saloon Keeper
    Posts: 7974
    143
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Yes, that's a good approach. However, if you want to access a file that's external to the JAR (also known as a user file), you should take care not to modify the path you get from the file chooser. In your SSCCE, you ask the user for a file path, then use only the file's name, and assume that it lives in a sub-directory of the user directory. That's NOT the file that the user chose, so it's not a surprise that it can't be found.

    That was actually the first hint for me when I debugged your program. I could reproduce your problems because the XML file I selected wasn't in some resource folder, but on my desktop.
     
    Stephan van Hulst
    Saloon Keeper
    Posts: 7974
    143
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Chris Crawford wrote:I thought that a resource was something embedded inside the "runnable JAR file". But the runnable JAR file that is built when I export the full program (not the SSCCE) is smaller than the XML file that is read.

    Yes it can be, because JARs are strongly compressed. However, it depends on whether you configured your Eclipse project to treat your XML file as a resource. If so, it will add it to the JAR.
     
    Chris Crawford
    Ranch Hand
    Posts: 116
    1
    Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I solved the problem by initializing the window with empty contents, then having the user Open the desired XML file. This worked. Then I went on to have more adventures with Java. At one point, seeing the behavior of the code, I resolved to purchase a large number of automatic weapons, travel to the building housing the Java team, and shoot the place up. However, after doing some physical labor in the forest, I realized that it was because of an oversight on my part. Oops.

    I am currently enjoying a new and even more exciting head-bashing-into-brick-wall experience. The code reads an XML element with two children, and concludes that there are actually five children there. Perhaps my CPU is having some problems with its ALU, adding 1 plus 1 and getting 5.  It then proceeds to do all sorts of impressive things with the three non-existent children. I won't bother you with the details; 99.9999999% of all the problems I have had with Java have ended up being pilot error, and I can't remember what that 0.00000001% is.

    Thanks for all the help.
     
    Stephan van Hulst
    Saloon Keeper
    Posts: 7974
    143
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    If you need help with your XML adventures, start a new topic and we'll see if we can sort you out.

    Good luck!
     
    Paul Clapham
    Sheriff
    Posts: 22828
    43
    Eclipse IDE Firefox Browser MySQL Database
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Chris Crawford wrote:The code reads an XML element with two children, and concludes that there are actually five children there.


    Typically this happens when the XML looks like this:



    Many people don't realize that the element there has five children. Two of them are elements and the other three are text nodes which consist of only whitespace.

    This element, on the other hand:



    does in fact have only two children.

    However if that isn't the pitfall you've fallen into then by all means, if you need to, post details about that problem. By the way we do have an XML forum, if your problem would be classified as an XML problem.
     
    Chris Crawford
    Ranch Hand
    Posts: 116
    1
    Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks for explaining that to me. It turns out that the structure of most of my other XML-reading code addresses the multiplicity of nodes correctly, but I had made a change in one place that ran afoul of that. I have now repaired it and gone on to other problems. So far, the two problems I have found both arise from misplacing an appendChild outside of its proper loop. Sometimes these deeply nested elements befuddle my aging mind. I really have to get out of programming and leave it to younger minds that can keep more details in mind simultaneously.
     
    It is sorta covered in the JavaRanch Style Guide.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!