import java.util.*;
class AddressBook {
private static final int DEFAULT_SIZE = 25;
private Person[] entry; //getting error - cannot be resolved to a type
public AddressBook() {
this( DEFAULT_SIZE);
}
public AddressBook(int size) {
if (size <= 0) {
throw new IllegalArgumentException("Size must be positive");
}
entry = new Person[size]; // cannot be resolved to a type
System.out.println("array of " + size + " is created");
}
}
import java.util.Scanner;
class TestAddressBook {
public static void main(String args[]) {
AddressBook myBook;
String inputStr;
int size;
Scanner scanner = new Scanner(System.in);
while(true) {
System.out.print("array size: " );
inputStr = scanner.next();
if (inputStr.equalsIgnoreCase("stop")) {
break;
}
size = Integer.parseInt(inputStr);
try {
myBook = new AddressBook(size);
}
catch (IllegalArgumentException e) {
}
System.out.println("Exception thrown: size = " + size);
}
}
}
我无法弄清楚我应该使用哪种类型的数组来使一切正常工作。 私人[]条目; //获取错误 - 无法解析为某种类型 .... entry = new Person [size]; //无法解析为类型
答案 0 :(得分:0)
人物定义在哪里?至少,添加以下内容:
class Person {}
将允许它编译。否则,它在您创建Person数组时不知道您的意思。
答案 1 :(得分:0)
这与数组无关(您可能想要更改问题标题)。你是:
实际错误可能会有所帮助。