对不起,初学者编码器在这里,我不擅长解释的东西,但我需要帮助,并想知道为什么我不断得到这个错误,无论我如何格式化或重新排列日期名称和标题。所以我只是想知道是否有人可以帮助我以什么顺序,我把名称日期和标题放在?我正在使用BlueJ编译器。找不到适合本书错误的构造函数?
这里是我的,我有问题的代码:
public BookStore()
{
inventory = new Book[100];
inventory[0] = new Book("James", "Joyce",2013,1,1, 2013,1,1, 2013,1,1, "ULYSSES");
inventory[1] = new Book(2013, "THE GREAT GATSBY", "F. Scott Fitzgerald");
我不断收到此错误发现书没有合适的构造(java.lang.String中,java.lang.String中,INT,INT ,int,java.lang.String)构造函数Book.Book()不适用; (实际和正式参数列表的长度不同);构造Book.Book(作者,日期,java.lang.String中)不适用(实际的和正式的参数列表的长度不同)
这里是Book类:
private static final String DEFAULT_TITLE = "Untitled";
private Author author;
private Date published;
private String title;
public Book()
{
this.author = new Author();
this.published = new Date();
this.title = DEFAULT_TITLE;
} // end constructor
public Book(Author author, Date published, String title)
{
setAuthor(author);
setDatePublished(published);
setTitle(title);
} // end constructor
public Author getAuthor()
{
return author;
} // end accessor
public Date getDatePublished()
{
return published;
} // end accessor
public String getTitle()
{
return title;
} // end accessor
public void setAuthor(Author author)
{
this.author = (null == author ? new Author() : author);
} // end accessor
public void setDatePublished(Date published)
{
this.published = (null == published ? new Date() : published);
} // end accessor
public void setTitle(String title)
{
this.title = (null == title ? DEFAULT_TITLE : title);
} // end accessor
public String getAuthorName()
{
return author.getName().getFullName();
} // end method
public String getDayOfTheWeekBookWasPublished()
{
return published.getDayOfTheWeek();
} // end method
public void printDetails()
{
System.out.print(getAuthorName());
System.out.print("(");
System.out.print(author.getName().getInitials());
System.out.print(") wrote ");
System.out.print(title);
System.out.print(" on ");
System.out.print(getDayOfTheWeekBookWasPublished());
System.out.print(", ");
System.out.print(Date.getMonthName(published.getMonth()));
System.out.print(" ");
System.out.print(published.getDay());
System.out.print(", ");
System.out.print(published.getYear());
Name pseudonym = author.getPseudonym();
if (null != pseudonym)
{
System.out.print(", under the pseudonym ");
System.out.print(pseudonym.getFullName());
}
System.out.println();
} // end method
} // end class
当你调用'new Book(“James”,“Joyce”,2013,1,1,2013,1,1,2013,1,1,“ULYSSES”)时,你试图调用哪个构造函数;'? – Pshemo
我假设它来自Book构造函数,对不起,就像我说过我是初学者编码器,我不太确定那就是为什么我发布了尽可能多的信息,因为我希望可以让人们更容易回答我的问题题。谢谢@Pshemo – Tre
初学者可以,所以不用担心。但试着回答我以前的问题。当你调用'New SomeClass(arguments)'时,'new'创建'SomeClass'的对象,然后调用'SomeClass(arguments)'中的代码来正确初始化它(设置它的字段,或者做一些其他你在构造函数)。但是由于'SomeClass'中可以有多个基于作为'arguments'传递的数据类型的构造函数,因此需要决定使用哪个构造函数。所以如果你传递'SomeClass(“Jack”,20)''它会试着找到'SomeClass(String,int)'而不是'SomeClass(Person)'。 – Pshemo