• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

No Suitable Constructor Found

 
Greenhorn
Posts: 4
Netbeans IDE Firefox Browser 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.
 
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
Netbeans IDE Firefox Browser 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
Netbeans IDE Firefox Browser 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.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • 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.
 
It will give me the powers of the gods. Not bad for a tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic