Results 1 to 20 of 26
- 11-02-2010, 11:14 AM #1
Member
- Join Date
- Jan 2010
- Posts
- 32
- Rep Power
- 0
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.
- 11-02-2010, 11:28 AM #2
have you used infinite for loop in your program?
Mak
(Living @ Virtual World)
-
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.
- 11-02-2010, 11:39 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 26
What you've done in the for loop and after the loop, can you show it here.
- 11-02-2010, 11:45 AM #5
Member
- Join Date
- Jan 2010
- Posts
- 32
- Rep Power
- 0
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]); }*/ } }
Last edited by ryuzog; 11-02-2010 at 11:55 AM.
- 11-02-2010, 11:50 AM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 26
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.
- 11-02-2010, 11:56 AM #7
Member
- Join Date
- Jan 2010
- Posts
- 32
- Rep Power
- 0
What would be the beginner's most common error to create a situation where a java program crashes without error?
- 11-02-2010, 12:00 PM #8
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 26
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.
- 11-02-2010, 12:07 PM #9
Member
- Join Date
- Jan 2010
- Posts
- 32
- Rep Power
- 0
"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.
- 11-02-2010, 12:29 PM #10
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 26
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-02-2010, 12:34 PM #11
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?
- 11-02-2010, 12:37 PM #12
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 26
That line 48 from the API, not from the OPs' code. Need to look at the complete stack to find it.
- 11-02-2010, 12:39 PM #13
Kinda hard to read a stack trace when its got a whole load of **** in the middle of it ^.^
- 11-02-2010, 12:41 PM #14
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 26
I agreed. This is because some of the exceptions are thrown out and some are not. And also the result formatting mess it up. :)
- 11-02-2010, 12:46 PM #15
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 26
I can't see that in the code, stack trace is printed. Normally stack is properly formatted by the VM.
- 11-02-2010, 12:47 PM #16
Member
- Join Date
- Jan 2010
- Posts
- 32
- Rep Power
- 0
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 - -;)
- 11-02-2010, 12:50 PM #17
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)
- 11-02-2010, 12:52 PM #18
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 26
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]);
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();
Looking at your code, it's really hard to debug as well, because of that you've large number of elements in arrays.
- 11-02-2010, 01:06 PM #19
Member
- Join Date
- Jan 2010
- Posts
- 32
- Rep Power
- 0
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~
- 11-02-2010, 01:14 PM #20
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 26
Rather posting an image of the error, could you please post the complete stack trace over here.
Similar Threads
-
How do I create a simple stop commmand in an elementary Java program?
By dillmann74 in forum New To JavaReplies: 10Last Post: 08-14-2010, 09:16 PM -
Use stop button to stop moving (stop timers) on JPanel
By mneskovic in forum New To JavaReplies: 3Last Post: 07-23-2010, 12:50 PM -
CMD is not reading commands
By colonial in forum Forum LobbyReplies: 1Last Post: 03-15-2010, 02:36 AM -
Need Help to Execute the commands from Java Program
By Anjaneyulu in forum Advanced JavaReplies: 7Last Post: 02-24-2010, 02:35 PM -
Java suddenly not working. Red X
By kd1516 in forum New To JavaReplies: 3Last Post: 10-23-2008, 05:23 AM
Bookmarks