我正在尝试编译将地址簿条目添加到我的数组中的代码。我有大部分的驱动程序,它接受名字和姓氏的输入,然后添加它们,并搜索某些值。我的问题是添加新条目的代码 - 我试图在地址簿中添加多个字符串作为一个条目,然后调用addEntry,但我收到以下错误...
C:\ Users \ Scherpich \ Desktop \ Jim School \ CS 219编程基础\程序\ ScherpichJamesTest2.java:17:错误:类SJAddressBook中的构造函数SJAddressBook不能应用于给定类型; aBook.add(new SJAddressBook()); ^ required:String,String 发现:没有争论 原因:实际和正式的参数列表长度不同
C:\ Users \ Scherpich \ Desktop \ Jim School \ CS 219 Programming Fundamentals \ Programs \ ScherpichJamesTest2.java:18:error:找不到符号 aBook.get(计数).addEntry(); ^ 符号:方法addEntry() location:类SJAddressBook
C:\ Users \ Scherpich \ Desktop \ Jim School \ CS 219 Programming Fundamentals \ Programs \ ScherpichJamesTest2.java:24:error:找不到符号 int foundIndex = abook.search(SJ); ^ 符号:变量SJ 位置:类ScherpichJamesTest2
C:\ Users \ Scherpich \ Desktop \ Jim School \ CS 219 Programming Fundamentals \ Programs \ ScherpichJamesTest2.java:24:error:找不到符号 int foundIndex = abook.search(SJ); ^ 符号:变量abook 位置:类ScherpichJamesTest2
C:\ Users \ Scherpich \ Desktop \ Jim School \ CS 219 Programming Fundamentals \ Programs \ ScherpichJamesTest2.java:30:error:找不到符号 SJ.get(foundIndex)。显示(); ^ 符号:变量SJ location:类ScherpichJamesTest2 。\ SJAddressBook.java:27:错误:缺少方法体,或声明抽象 public static int search(ArrayListaBook); ^ 。\ SJAddressBook.java:34:错误:找不到符号 int choice = integer.parseInt(entry.nextLine()); ^ 符号:变量整数 location:类SJAddressBook 。\ SJAddressBook.java:38:error:找不到符号 for(SJAddressBook地址:aBook) ^ 符号:变量aBook location:类SJAddressBook 。\ SJAddressBook.java:44:错误:返回外部方法 return aBook.IndexOf(Address); ^ 。\ SJAddressBook.java:47:错误:找不到符号 如果(value.equalisIgnoreCase(Address.LAST)) ^ 符号:方法equalisIgnoreCase(String) location:String类型的变量值 。\ SJAddressBook.java:48:error:返回外部方法 return aBook.IndexOf(Address); ^ 。\ SJAddressBook.java:53:错误:返回外部方法 返回-1; ^ 12个错误
这是我的主要方法类
{
public static void main(String[] args)
{
ArrayList<SJAddressBook> aBook = new ArrayList<SJAddressBook>();
for (int count =0;count <3;count ++)
{
aBook.add(new SJAddressBook());
aBook.get(count).addEntry();
System.out.println();
}
int foundIndex = abook.search(SJ);
System.out.println();
if (foundIndex > -1)
SJ.get(foundIndex).display();
else
System.out.println("No Entry Found");
}
}
//我的驱动程序类
public class SJAddressBook //start class definition
{
static String FIRST;
private String LAST;
public SJAddressBook(String first, String last)
{
Scanner entry = new Scanner (System.in);
System.out.print("Please Enter First Name: ");
FIRST = entry.nextLine();
System.out.print("Please Enter Last Name: ");
LAST = entry.nextLine();
}
public static int search(ArrayList<SJAddressBook>aBook);
{
Scanner entry = new Scanner (System.in);
System.out.println("1. First Name");
System.out.println("2. Last Name");
System.out.print("Please Enter Field to Search: ");
int choice=integer.parseInt(entry.nextLine());
System.out.println("Please enter value to search for: ");
String value=entry.nextLine();
for(SJAddressBook Address: aBook)
{
switch(choice)
{
case 1:
if(value.equalsIgnoreCase(Address.FIRST))
return aBook.IndexOf(Address);
break;
case 2:
if(value.equalisIgnoreCase(Address.LAST))
return aBook.IndexOf(Address);
break;
}
}
return -1;
}
public void display()
{
System.out.println("First Name: "+this.FIRST);
System.out.println("Last Name: "+this.LAST);
}
}
答案 0 :(得分:2)
C:\ Users \ Scherpich \ Desktop \ Jim School \ CS 219编程基础\程序\ ScherpichJamesTest2.java:17:错误:类SJAddressBook中的构造函数SJAddressBook不能应用于给定类型; aBook.add(new SJAddressBook()); ^ required:String,找到的字符串:无参数原因:实际和形式参数列表的长度不同
new SJAddressBook ()
作为空构造函数,该类的唯一构造函数需要2个参数SJAddressBook (String first, String last)
C:\ Users \ Scherpich \ Desktop \ Jim School \ CS 219 Programming Fundamentals \ Programs \ ScherpichJamesTest2.java:18:error:找不到符号aBook.get(count).addEntry(); ^符号:方法addEntry()location:类SJAddressBook
addEntry ()
。通过调用 aBook.get(count),您将在 get(count)位置返回 SJAddressBook 。C:\ Users \ Scherpich \ Desktop \ Jim School \ CS 219 Programming Fundamentals \ Programs \ ScherpichJamesTest2.java:24:error:找不到符号int foundIndex = abook.search(SJ); ^符号:变量SJ位置:类ScherpichJamesTest2
C:\ Users \ Scherpich \ Desktop \ Jim School \ CS 219 Programming Fundamentals \ Programs \ ScherpichJamesTest2.java:24:error:找不到符号int foundIndex = abook.search(SJ); ^符号:变量abook位置:类ScherpichJamesTest2
C:\ Users \ Scherpich \ Desktop \ Jim School \ CS 219 Programming Fundamentals \ Programs \ ScherpichJamesTest2.java:30:error:找不到符号SJ.get(foundIndex).display(); ^符号:变量SJ位置:类ScherpichJamesTest2
。\ SJAddressBook.java:27:错误:缺少方法体,或声明抽象的public static int search(ArrayListaBook); ^
public static int search(ArrayList<SJAddressBook>aBook);
。\ SJAddressBook.java:34:错误:找不到符号int choice = integer.parseInt(entry.nextLine()); ^符号:变量整数位置:类SJAddressBook
。\ SJAddressBook.java:38:错误:找不到符号(SJAddressBook地址:aBook)^符号:变量aBook位置:类SJAddressBook
。\ SJAddressBook.java:44:错误:返回外部方法返回aBook.IndexOf(Address); ^
。\ SJAddressBook.java:47:错误:找不到符号if(value.equalisIgnoreCase(Address.LAST))^符号:方法equalisIgnoreCase(String)位置:String类型的变量值
。\ SJAddressBook.java:48:错误:返回外部方法返回aBook.IndexOf(Address); ^
。\ SJAddressBook.java:53:错误:返回外部方法返回-1; ^ ; 12个错误