私はこのJavaコードを持っています
public class SlumbookDriver{
public static void main(String args[]){
Slumbook[] contacts = new Slumbook[19];
autoAdd();
String con1 = contacts[0].viewToString();
System.out.println(con1);
}
メソッド autoAdd を次のように使用します
public static void autoAdd(){
contacts[0] = new Slumbook("2014-0002", "Karl Marx", "Karly", "German", "Cologne",
"House", "2358681", "Single", "N/A", "Karl_Marx@yahoo.com");
contacts[1] = new Slumbook("2015-0006", "Fidel Castro", "Strong Man of Cuba", "Cuban",
"Cuba", "Lungon", "7863264", "Married", "Dead", "FidelCatro@msn.com");
}
}
実行しようとすると、次のようにメイン内で配列を割り当てると、コードerror: Cannot find Symbol
であるシンボルがvariable contacts
正しく機能すると表示されます。
public class SlumbookDriver{
public static void main(String args[]){
Slumbook[] contacts = new Slumbook[19];
contacts[0] = new Slumbook("2014-0002", "Karl Marx", "Karly", "German", "Cologne",
"House", "2358681", "Single", "N/A", "Karl_Marx@yahoo.com");
contacts[1] = new Slumbook("2015-0006", "Fidel Castro", "Strong Man of Cuba", "Cuban", "Cuba", "Lungon", "7863264", "Married", "Dead", "FidelCatro@msn.com");
String con1 = contacts[0].viewToString();
System.out.println(con1);
}
しかし、それは私が望むものではありません