~ Mansukh
Bora Sabrioglu wrote:Hi there,
this is the relevant code snippet:
...
inputBuffer = new BufferedReader(new FileReader(inputFile)); //lineA
testcases_T = Integer.parseInt(inputBuffer.readLine()); //lineB
...
When I'm in debug mode line A compiles fine and it even shows the correct value for the first String (1000) that i watch in the Tab "Expressions" in Eclipse (i added a watch for inputBuffer.readline()).
But when I try to compile lineB it throws this:
java.lang.NumberFormatException: For input string: "138 844"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at competition.gcj2013.round1A.BullsEye.main(BullsEye.java:30)
The input file is like this:
1000
138 844
....
so it kinda "ignores" or "jumps over" the first line???
I'm not getting this... help is really appreciated.
Thanks in advance!
~ Mansukh
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
at test.BullsEye.main(BullsEye.java:31)
~ Mansukh
~ Mansukh
~ Mansukh
Bora Sabrioglu wrote:when I run it, it goes into infinite loop as you said... and when I try to debug, it throws the exception posted above
( it says:
java.lang.NumberFormatException: For input string: "138 844"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at competition.gcj2013.round1A.BullsEye.main(BullsEye.java:30)
whereas the 30 refers to the line testcases_T = Integer.parseInt(inputBuffer.readLine());
)
If I can get over this initial hurdle, I can handle the debugging of the program myself, but I don't know why it does not read the first item of the input file (which is '1000').
~ Mansukh
inputBuffer = new BufferedReader(new FileReader(inputFile)); //lineA
testcases_T = Integer.parseInt(inputBuffer.readLine()); //lineB
...
When I'm in debug mode line A compiles fine and it even shows the correct value for the first String (1000) that i watch in the Tab "Expressions" in Eclipse (i added a watch for inputBuffer.readline()).
But when I try to compile lineB it throws this:
java.lang.NumberFormatException: For input string: "138 844"
Since area A = Pi*radius *radius and you can use 1 ml for Pi cm2 you can exclude Pi from the calculation altogether.
~ Mansukh
~ Mansukh
~ Mansukh
Bora Sabrioglu wrote:Please set a breakpoint to the first line after the try-clause (09. inputBuffer = ...) ... then press F6 for 'Step Over' if you're using Eclipse so it goes to the next line (10. testcases_T = ...) and then press F6 again (if you're using Eclipse)....
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
AFAICG you also still haven't explained why you're skipping that first line - which is a number.
Bora Sabrioglu wrote:
Winston Gutkowski wrote:
AFAICG you also still haven't explained why you're skipping that first line - which is a number.
Thats why I opened this thread in the first place... because I don't get it myself why it is skipping it.
So Mansukhdeep is debugging it and it throws no exception.
Since when Mansukhdeep is debugging it, as we can see from the snapshot: IT READS THE FIRST LINE, "1000" !
I have the same code, the same input file and it is throwing an NFE since it skips the first line somehow (which contains the string "1000"), that's why the NFE is thrown.
Obviously it doesn't make sense trying to solve the problem, if you're getting different outcome when debugging, than you're supposed to get.
So we have to solve that problem first. Then we can proceed and solve the actual problem.
Mansukhdeep, can you tell me which environment you use (which IDE, is it Juno, Indigo? and then which JRE, which JDK, etc...)
I think I have to uninstall everything and then install again...
~ Mansukh
Bora Sabrioglu wrote:but we have the same input file, the same source code, everything is the same... but still it skips the first line in my case, in yours it doesn't... hmm... I have no clue why it does that.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Bora Sabrioglu wrote:I just installed Eclipse Juno and JDK 7 at my nephews laptop.... it debugs beautifully, as shown in the snapshot from Mansukhdeep...
So in this case it is a local problem with my environment, it has nothing to do with the sourcecode.
I will deinstall Eclipse and the JDK and install everything from scratch at my own machine... then I will see if I get the same result there... if so, then I will be able to solve that problem, since I will be able to debug properly then... and then I will print the result here since I promised it
Thanks for everyone who helped me out, especially for Mansukhdeep who invested quite some time and efforts... thanks alot
~ Mansukh
Dinner will be steamed monkey heads with a side of tiny ads.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|