• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

exception in thread "main"

 
Ben Hultin
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
working on my first OOP program and I am now getting an exception with my method input().




Please enter info about your first cat.
Enter a cats name:
Jenni
Enter cats age:
4
Enter cats weight:
7.4
Enter cats breed:
Tabby
Is your cat declawed? True or False
true


Please enter info about your second cat.
Enter a cats name:
Joe Joe
Enter cats age:
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at Cat.input(Cat.java:75)
at HultinBenWeek6Prog.main(HultinBenWeek6Prog.java:113)





I am trying to use the same questions in three different objects which have all been put inside one method input().

the input method: found in my driven class Cat inside Cat.java



object and method call: found inside driver class




Thanks a lot for your help
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12102
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what, exactly, are you typing for each input?
 
Ben Hultin
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you meaning the user input?


Enter a cats name:
Jenni // user input for name

Enter cats age:
4 // user input for age

Enter cats weight:
7.4 // user input for weight

Enter cats breed:
Tabby // user input for breed

Is your cat declawed? True or False
true // user input for declawed




Here is my setter methods that may help with determining the problem.


 
Hiruka Sandev
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ben Hultin wrote:
Enter a cats name:
Joe Joe


The default delimiter in a Scanner is a whitespace. I'm guessing you are using the default delimiter, in which case 'Joe Joe' is considered as two inputs.
 
Ben Hultin
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh god, that thing again... I need to remember that! Thanks a lot for reminding me. It works now
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic