我的代码中有什么错误?代码未编译,仅在add.persons(p);
import javax.swing.*;
public class AddressBook
{
ArrayList personInfo;
public AddressBook()
{
persons=new ArrayList();
}
public void addperson()
{
String name= JOptionPane.showInputDialog("Enter name of the person ");
String address=JOptionPane.showInputDialog("Enter address of the person ");
String phoneNum =JOptionPane.showInputDialog("Enter phone number of the person ");
}
personInfo p = new personInfo(name, address, phoneNum);
persons.add(p);
public void searchPerson(String n)
{
for (int i = 0; i<persons.size(); i++)
{
PersonInfo p= (personInfo)person(i);
if (n.equals(p.name))
{
p.printPersonInfo();
}
}
}
public void deletPerson(String n)
{
for (int i = 0; i<persons.size(); i++)
{
PersonInfo p= (personInfo)person(i);
if (n.equals(p.name))
{
person.remove(i);
}
}
}
}
答案 0 :(得分:2)
移动这个
personInfo p = new personInfo(name, address, phoneNum);
persons.add(p);
在方法中,一切都会起作用....