Page 1 of 2 12 LastLast
Results 1 to 20 of 26
  1. #1
    ryuzog is offline Member
    Join Date
    Jan 2010
    Posts
    32
    Rep Power
    0

    Default What can cause of java program to suddenly stop reading commands?

    I have a "for" loop:

    for(***) {
    //do stuff
    System.out.println("testing stuff...");
    }
    System.out.println("continue to do stuff");

    When I run it, the build is successful and "testing stuff..." is successfully printed, however, this is when the program stops for seemingly no reason, it doesn't print "continue to do stuff".

    What's frustrating is that after the final system output, instead of "Program stopped, here's the error." It says "build successful".

    Now there are some errors up top in the //do stuff part, but I can't figure them out, they have to do with number format exceptions but they don't seem to affect my goals directly. (I have a test command after each action and it shows the proper result). Also they point to errors outside my code, to linee in native functions.

    Is it some bug in the beginning that caused some sort of fatal crash near the end? Shouldn't it give some sort of hint as to the error?

    Heres a line I can sort of make sense of, but I don't know what it's referring to:
    ( Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "")
    Last edited by ryuzog; 11-02-2010 at 11:17 AM.

  2. #2
    makpandian's Avatar
    makpandian is offline Senior Member
    Join Date
    Dec 2008
    Location
    Chennai
    Posts
    396
    Rep Power
    6

    Default

    have you used infinite for loop in your program?
    Mak
    (Living @ Virtual World)

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

    Default

    Without seeing more code and in particular the code causing the NumberFormatException, I don't think any of us will magically be able to tell you where your bug is.

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  5. #5
    ryuzog is offline Member
    Join Date
    Jan 2010
    Posts
    32
    Rep Power
    0

    Default

    It's not an infinite loop.

    I suppose by this reaction I'm assuming that such an error is a rarity and that standard cookie cutter advice won't help?

    I don't need a surgeons scalpel(nor do I believe in magic). A good start would be WHY a java program stop running giving no sign of an error? C for example has some strange stuff to do with pointers and memory but java is a relatively "safe" program and this type of error I have never heard of, thus I don't know how to deal with it.

    The two system.out.prints are separated by ONE bracket, does that not narrow down the potential areas for error at all?
    Here's the portion of the code
    Java Code:
    if (e.getSource() == extractButton){
                 int returnVal = fc.showOpenDialog(CompressorUI.this);
                 char[] inputArray = null;
                 int[] binaryArray = null;
                 if (returnVal == JFileChooser.APPROVE_OPTION) {
                    File file = fc.getSelectedFile();
                    log.append("You have Chosen: \"" + file.getName() + "\" to uncompress.\n" );
    
                    try  {
                           BufferedReader in = new BufferedReader(new FileReader(file));
    
                           String input;
                           inputArray = new char[(int)file.length()];
    
                           for(int i=0; i<256;i++){
                                 input = in.readLine();
                                 charFreqs[i] = Integer.valueOf(input);
                           }//get charFreqs to recreate huffman tree
    
                           while(true){
                             //read till end of file, break at null
                             input = in.readLine();
                             if (input == null)
                                 break;
    
                             for(int i = 0; i <input.length() ; i++){
                                 inputArray[i] = input.charAt(i);
                                 //System.out.println("inputarray: " + i + " equals " +input.charAt(i));
                                 }//get rest of input
    
                            }//end "while"
                                 in.close();
                            }  catch (IOException w) {
                          }
    
                      //input array now contains the file sequence, proceed to expand hex into binary
                      binaryArray = new int[4*inputArray.length];
                      int binaryCounter = 0;
                      
                      //recreate huffman tree
                      HuffmanTree tree = null;
                      tree = HuffmanTree.buildTree(charFreqs);
                      //System.out.println("Testing this Huffman Tree yadayada");
                      //HuffmanTree.print(tree, new Stack<Character>());
    
              for(int i = 0; i < inputArray.length; i ++){//create a binary array from input
                   
                      //hex to integer
                      int intHex = Integer.valueOf((Character.toString(inputArray[i])),16).intValue();                 
    
                      //integer to binary...
                      if(intHex>=8){
                       binaryArray[binaryCounter] = 1;
                       binaryCounter++;
                       System.out.print(1);
                       intHex -= 8;
                       }
                      else{
                         binaryArray[binaryCounter] = 0;
                         binaryCounter++;
                         System.out.print(0);
                          }
                      if(intHex>=4){
                       binaryArray[binaryCounter] = 1;
                       binaryCounter++;
                       System.out.print(1);
                       intHex -= 4;
                       }
                      else{
                          binaryArray[binaryCounter] = 0;
                          binaryCounter++;
                          System.out.print(0);
                          }
                      if(intHex>=2){
                       binaryArray[binaryCounter] = 1;
                       binaryCounter++;
                       System.out.print(1);
                       intHex -= 2;
                       }
                      else{
                          binaryArray[binaryCounter] = 0;
                          binaryCounter++;
                          System.out.print(0);
                          }
                      if(intHex>0){
                       binaryArray[binaryCounter] = 1;
                       binaryCounter++;   
                       System.out.print(1);
                          }
                      else{
                          binaryArray[binaryCounter] = 0;
                          binaryCounter++;
                          System.out.print(0);
                          }
                      System.out.println(" binaryArray" +binaryCounter+ "= " + binaryArray[binaryCounter-1]+","+ "binaryArray" +(binaryCounter-2)+ "= " + binaryArray[binaryCounter-2]+","+"binaryArray" +(binaryCounter-2)+ "= " + binaryArray[binaryCounter-3]+"," +"binaryArray" +(binaryCounter-3)+ "= " + binaryArray[binaryCounter-4]);
                }//end "for"
    
                System.out.println("WHY DOES THE PROGRAM STOP HERE!!");
                /*char[] translated = HuffmanTree.translateBinary(binaryArray, tree);
                for(int i=0; i<translated.length;i++){
                    System.out.print(translated[i]);
                }*/
                    
                }
            }
    The sentence "Why does the program stop here" doesn't print so I can't test my translateBinary function. The rather complicated system.out.println above it is just for testing and shows that binaryArray is properly created. (There are a bunch of errors, but I don't know what they refer to.)
    Last edited by ryuzog; 11-02-2010 at 11:55 AM.

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Don't mess-up with Java and C (or C++). In Java you don't need to worry about memory management and all. VM done it for you. So sometimes applications crash without any error. (sometime C/C++ application does)

    No one here in the forum are magicians, to imagine how your code is and what it does. You must provide more details. Otherwise it's not an easy task to comment on your question.

  7. #7
    ryuzog is offline Member
    Join Date
    Jan 2010
    Posts
    32
    Rep Power
    0

    Default

    What would be the beginner's most common error to create a situation where a java program crashes without error?

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    What's the last line of text that you can see on your console?

    There is no such common error cause to stop the execution, unless by mistake done it in the application.

  9. #9
    ryuzog is offline Member
    Join Date
    Jan 2010
    Posts
    32
    Rep Power
    0

    Default

    "Build Successful"

    then it just stops. So a print succeeds, then after a bracket, the second print just disappears.

    EDIT: Here's a screen shot of a small portion of the resulting output to the console, there are some thousand lines and most, probably 70%+ have no errors, there doesn't seem to be anything differencing why some lines lead to an error, the calculations are all pretty much the same..

    <img src="http://imgur.com/sGEv8.png" alt="" title="Hosted by imgur.com" />

    http://imgur.com/sGEv8.png

    Here's one of the last few lines, no error, usually a "build successful" here in green at the end. Right after this looped thousand line printing there's one more line that says: "Why won't this print", that won't print.


    http://imgur.com/XrJMu.png

    What causes a random "stop" like this? a memory error?
    Last edited by ryuzog; 11-02-2010 at 12:21 PM.

  10. #10
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Did you see that in the result, there is a NumberFormatException. That could lead to a memory error as well. Because even after the error you've push data.

    And also I can see that you've use arrays in huge size. Those are arrays or ArrayLists ?

  11. #11
    berkeleybross's Avatar
    berkeleybross is offline Senior Member
    Join Date
    Feb 2010
    Location
    England
    Posts
    187
    Rep Power
    5

    Default

    If a thread throws an exception without it being caught, it will usually be stopped.
    If it is the only thread, then the program will also stop.

    A memory error is most likely NOT the cause of this. Those happen once in a blue moon. You should look to see if there are errors in your code, then look for errors elsewhere.

    You should deal with your number format exception, and that should mean the program will run correctly.

    We dont know what line 48 is, so please could you paste that line?

  12. #12
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    That line 48 from the API, not from the OPs' code. Need to look at the complete stack to find it.

  13. #13
    berkeleybross's Avatar
    berkeleybross is offline Senior Member
    Join Date
    Feb 2010
    Location
    England
    Posts
    187
    Rep Power
    5

    Default

    Kinda hard to read a stack trace when its got a whole load of **** in the middle of it ^.^

  14. #14
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    I agreed. This is because some of the exceptions are thrown out and some are not. And also the result formatting mess it up. :)

  15. #15
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    I can't see that in the code, stack trace is printed. Normally stack is properly formatted by the VM.

  16. #16
    ryuzog is offline Member
    Join Date
    Jan 2010
    Posts
    32
    Rep Power
    0

    Default

    Is the problem within this section of the code or elsewhere?

    I had a feeling that the main problem is the number format exception, except that as Eranga said it's from the API, so I'm not sure where it's coming from.

    (The thing deals with 1's and 0's for a thousand iterations or so, popping up random errors after - -;)

  17. #17
    berkeleybross's Avatar
    berkeleybross is offline Senior Member
    Join Date
    Feb 2010
    Location
    England
    Posts
    187
    Rep Power
    5

    Default

    Im not sure where the problem is..
    Somewhere in your code, you seem to trying to convert an empty string into an integer, which cannot be done.

    Could you comment out all your println() statements and repost the error messages.
    They are usually very helpful in pinpointing the error, but they are hard to read at the moment.

    The reason they look like this is because two different threads are trying to use the console, so it turns into a race condition (badly implemented :P)

  18. #18
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Try to narrow down it.

    Java Code:
    System.out.println(" binaryArray" +binaryCounter+ "= " + binaryArray[binaryCounter-1]+","+ "binaryArray" +(binaryCounter-2)+ "= " + binaryArray[binaryCounter-2]+","+"binaryArray" +(binaryCounter-2)+ "= " + binaryArray[binaryCounter-3]+"," +"binaryArray" +(binaryCounter-3)+ "= " + binaryArray[binaryCounter-4]);
    You display the result here in above line, right?

    Try to simplify that first of all. See how it is complex, really hard to even read it second time. Comment it at the moment.

    Java Code:
    int intHex = Integer.valueOf((Character.toString(inputArray[i])),16).intValue();
    Then check these conversions. Put a clear print statement to check values, if you cannot debug the code.

    Looking at your code, it's really hard to debug as well, because of that you've large number of elements in arrays.

  19. #19
    ryuzog is offline Member
    Join Date
    Jan 2010
    Posts
    32
    Rep Power
    0

    Default

    Ok I'll check some things out:

    1)Will check if I am converting empty string to integer somewhere
    2)Will check hex conversion (just googled it actually, I believe I tested it though...)


    http://imgur.com/It7Ag.png
    (I always believed the first error to be the most important one, usually helped since it pointed out the actual line where the error occurs, this situation is vexing though)

    Currently rather late in my timezone, will check back in tomorrow. Thanks for all the help and advice so far~

  20. #20
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 10
    Last Post: 08-14-2010, 09:16 PM
  2. Use stop button to stop moving (stop timers) on JPanel
    By mneskovic in forum New To Java
    Replies: 3
    Last Post: 07-23-2010, 12:50 PM
  3. CMD is not reading commands
    By colonial in forum Forum Lobby
    Replies: 1
    Last Post: 03-15-2010, 02:36 AM
  4. Need Help to Execute the commands from Java Program
    By Anjaneyulu in forum Advanced Java
    Replies: 7
    Last Post: 02-24-2010, 02:35 PM
  5. Java suddenly not working. Red X
    By kd1516 in forum New To Java
    Replies: 3
    Last Post: 10-23-2008, 05:23 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
  •