• Post Reply Bookmark Topic Watch Topic
  • New Topic

Missmatchexception..  RSS feed

 
Daniel Ungerfält
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
Starting to get mad here.. Was just putting up a simple loop to try store values but got this missmatch error after second time I type in a name.



 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What line causes the MismatchException? In the for loop or outside it?

If for loop, maybe getting inputs on 2 different lines is better.

Also why is Person class need the super(), it's implicit cos the super class is Object.

 
Daniel Ungerfält
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fixed it! I had to use name = s.next(); instead of s.nextLine(); cause that just skipped to the next intput( s.nextInt();)
 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The reason for that is that the behaviour of nextLine is not at all well documented. Start by looking at this old post of mine. That will probably explain why you are one entry out from where you expected to be. It also suggests a solution.

And while we are at it, move most of that code out of the main method and remove every other occurrence of the keyword static from that class.

Why do you keep changing your Person class? Every change you make seems to be for the worse. The first version you showed was the best, but it needed a constructor adding. Mark all fields private. Add the getXXX methods, toString etc. Consider whether you need setXXX methods; I am sure I have explained them to you already.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!