aspose file tools*
The moose likes Beginning Java and the fly likes exception in thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "exception in thread "main"" Watch "exception in thread "main"" New topic
Author

exception in thread "main"

Ben Hultin
Ranch Hand

Joined: Aug 17, 2009
Posts: 135
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

Joined: Oct 02, 2003
Posts: 11308
    
  16

what, exactly, are you typing for each input?


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Ben Hultin
Ranch Hand

Joined: Aug 17, 2009
Posts: 135
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

Joined: Nov 22, 2009
Posts: 11
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

Joined: Aug 17, 2009
Posts: 135
oh god, that thing again... I need to remember that! Thanks a lot for reminding me. It works now
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: exception in thread "main"