我的java代码中的错误是什么。没有编译

时间:2016-11-14 10:00:07

标签: java

我的代码中有什么错误?代码未编译,仅在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);
                }

            }
        }
}

1 个答案:

答案 0 :(得分:2)

移动这个

personInfo p = new personInfo(name, address, phoneNum);
persons.add(p);

在方法中,一切都会起作用....