• Post Reply Bookmark Topic Watch Topic
  • New Topic

constructor problems  RSS feed

 
Ben Hultin
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am compiling a program, but as of now I am getting back a lot of errors telling me unfound constructors:



BenHultinWeek5CatMouse.java:13: cannot find symbol
symbol : constructor Mouse()
location: class Mouse
mice.add(new Mouse());





This program is spread out over a few different files.

My Driver:




My driven file Mouse:




While as you may notice that Mouse is a subclass of the superclass Mammal, I have left out the file believing it has no bearing on this compilation error at hand.

I appreciate the help
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, the error message is clear: the compiler cannot find the constructor for class Mouse that takes no arguments. Your class Mouse has a constructor that takes two arguments: int a, double w. It doesn't have a constructor that takes no arguments, so the compiler complains.

Either add the arguments to the line where you create a new Mouse object, for example:

Or add a constructor to class Mouse that takes no arguments.
 
Ben Hultin
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks a lot for the help, that made perfect sense. I will remember this in the future.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
something else to remember...if you don't create ANY constructors, a no-argument is created for you automagically (although it may not do exactly what you want).

If you write ANY constructors, you don't get the free one. So if you write a 2 argument constructor, you have to write a 0-argument one yourself (if you need it).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!