• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

exception in thread "main"

 
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.


 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oh god, that thing again... I need to remember that! Thanks a lot for reminding me. It works now
reply
    Bookmark Topic Watch Topic
  • New Topic