• Post Reply Bookmark Topic Watch Topic
  • New Topic

No Suitable Constructor Found  RSS feed

 
Fred Schaefer
Greenhorn
Posts: 4
Firefox Browser Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm new to programming in Java and I'm trying to learn from online sources. I've come up with a error code that I'm not sure how to fix.


I would appreciate any help on fixing this problem.
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Fred. Welcome to the Ranch!

So you're getting an error about a constructor. This is the only use of a constructor on that line:


tempArray is a String[], so tempArray[0] (etc) is a String. That means that this is trying to use a constructor ListOfPeople(String, String, String).

So what constructors does ListOfPeople have? You've got a ListOfPeople(String) and ListOfPeople(String, String, String, String). Does either of those match the one you are trying to use?
 
Fred Schaefer
Greenhorn
Posts: 4
Firefox Browser Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the welcome Matthew.

I'm not sure where to put the constructor. I thought I had put the constructor in line 35. If I were to make everything public, would it change the need for a constructor?
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fred Sc wrote: I thought I had put the constructor in line 35.

Yes, you've added a constructor. It takes 4 arguments. You then tried to create use it using only three arguments.

Constructors aren't special in this respect - it would be the same with an ordinary method. If it expects 4 arguments then you need to call it with 4 arguments.
 
Fred Schaefer
Greenhorn
Posts: 4
Firefox Browser Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow! I had only put in 3 constructors to make sure I was getting my syntax correct. What a simple fix to add one more!

I would assume the reverse would be true also? In line 35, if I had only put 2 constructors in, say String fname, String lname and no others; then I would still get an error in line 30 because it's looking for 3 constructors correct?

Thanks for helping me fix my little problem.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note the terminology: you don't have 3 constructors, you have one constructor, that takes 4 parameters: fname, lname, fcolor and DOB.

What was wrong is that you tried to use that constructor by passing 3 arguments. That won't work, because it needs 4, not 3 arguments. You need to specify values for all 4: fname, lname, fcolor and DOB.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!