2012-04-22 4 views
0

내가 만든 클래스로 연결된 목록이 있지만 목록에 새 인스턴스를 추가 할 때마다 목록의 다른 모든 요소가 동일한 데이터를 가져옵니다.Java 클래스의 여러 인스턴스가 최신 인스턴스로 재설정됩니다.

여기 내 목록에있는 수업이 있습니다.

public class ZitEntity 
{ 
private int mSize; 
public boolean poped; 
private boolean done; 
private Canvas can; 
private int count; 
private static Vector2D mPosition; 
private int ms; 
private Bitmap Zit; 

public ZitEntity(int a, int b) 
{ 
    mSize = 20; 
    poped = false; 
    done = true; 
    ms = 3; 
    mPosition = new Vector2D(a,b); 
    Zit = Bitmap.createBitmap(mSize*2, mSize*2, Bitmap.Config.ARGB_8888); 
} 

두 번째 클래스에서는 목록을 만듭니다.

private LinkedList<ZitEntity> entityList; 

그리고 생성자에서 목록을 시작합니다. 나는 목록에 새 인스턴스를 추가 할 경우 여기

entityList = new LinkedList<ZitEntity>(); 

그리고는 다음과 같습니다

private void createEntity() 
{ 
    Random generator = new Random(); 
    int a = generator.nextInt(10); 
    if(a==5) 
    { 
     int x = generator.nextInt(ZitGame.height-60)+20; 
     int y = generator.nextInt(ZitGame.width-120)+20; 
     entityList.add(new ZitEntity(x,y)); 
     Log.v("add entity", "new entity"); 
    } 
} 

답변

3

이 같은 정적 mPosition를 선언, 그래서 때마다 각 항목에 대한 최신 위치를 얻을 것이다

관련 문제