我试图将对象添加到我的ArrayList的朋友......我得到这个错误,为什么我添加对象时ArrayList中我得到这个错误 - Java的
Add方法(INT,人)的ArrayList类型不 适用于参数(INT,字符串)
我试图加我的人对象的少数情况下,最终创建的朋友一棵树。
import java.util.*;
public class Person
{
public int id; // some identification number unique to the person
public boolean zombie; // true if the person is a zombie
public char state; // p means human, z means zombie
public static ArrayList<Person> friends; // list of friends
public Person(int id, char state)
{
this.id = id;
this.state = state;
//this.zombie = zombie;
}
public static void addPeople()
{
friends = new ArrayList<Person>();
friends.add(1, 'p');
}
public boolean isZombie()
{
if (state == 'p')
{
return zombie=false;
}
else if (state == 'z')
{
return zombie=true;
}
return zombie;
}
}
错误位于“添加”字下。我也想知道如何命名对象的实例,所以我只调用名称而不是两个属性。
在此先感谢您的帮助。
每次都不会重新初始化“好友”,您会删除旧条目。 – Mordechai 2013-04-03 22:44:54