• Post Reply Bookmark Topic Watch Topic
  • New Topic

How do I fix this weird run time error?  RSS feed

 
Matrica Kovolunchy
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I was making a program for a class I have an encountered an odd run time error. The program does compile without errors. The runtime error is:

C:\Users\ttlj\Desktop>java MixMatch lab9.txt lab9a.txt
Please enter two files separated by a space
java.util.Scanner[delimiters=\p{javaWhitespace}+][position=0][match valid=true][
need input=false][source closed=true][skipped=false][group separator=\,][decimal
separator=\.][positive prefix=][negative prefix=\Q-\E][positive suffix=][negati
ve suffix=][NaN string=\Q?\E][infinity string=\Q?\E]
java.util.Scanner[delimiters=\p{javaWhitespace}+][position=0][match valid=true][
need input=false][source closed=false][skipped=false][group separator=\,][decima
l separator=\.][positive prefix=][negative prefix=\Q-\E][positive suffix=][negat
ive suffix=][NaN string=\Q?\E][infinity string=\Q?\E]


Here is the code.



As always, thank you for your time!
 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no error in the output that you posted. You are printing out the Scanner object in your code and that is what s being printed out.
Perhaps you wanted to get values from the Scanner with

?
 
Campbell Ritchie
Marshal
Posts: 56520
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you look at the output, you will see that is the description of the scanner. Not the next line. You have told the runtime to print the Scanner, when you should print the line read.
 
Campbell Ritchie
Marshal
Posts: 56520
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Exactly what E Armitage told you before me
 
Stuart A. Burkett
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is also a subtle error in line 32. Do you know the difference between = and ==.
In this case it doesn't really matter because lines 32 - 35 are redundant. The while loop will exit as soon as moreLines is false, so there is no need for the break.
 
Campbell Ritchie
Marshal
Posts: 56520
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never write == false or == true. Not only are they ugly style, but also (as you can see above) error‑prone. I never noticed that error, thank you SAB for pointing it out.
It is never if (b == true) ... nor if (b == false) ...
It is always if (b) ... and if (!b) ...
 
Paweł Baczyński
Bartender
Posts: 2074
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Little offtop.
I once encountered this kind of monster in code I was working on.
if(!(condition != false))
Weird...
Or was it a joke a programmer left for others...
 
Campbell Ritchie
Marshal
Posts: 56520
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pawel Pawlowicz wrote: . . . if(!(condition != false))
Weird...
Or was it a joke a programmer left for others...
It probably is visible on 31st October, and you can't see it today
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!