1

Possible Duplicate:
cannot make a static reference to the non-static field

I had created this code here: http://mibpaste.com/naGV58 using arraylists to succeed the desired result. As you can see each agent attaches to another one using the arrive(PVector); method.

I tried to reconfigure the whole process by implementing inheritance and polymorpism in order to create some subclasses etc. The new code here: http://mibpaste.com/WwZBWz generates a problem when I try to apply a specific method. The bug is:

cannot make a static reference to the non-static field MW2.location

Do you have any idea how to solve it? I think I have to create new objects from each subclass but I do not know how...

Anything I have tried has already failed. I 'm not even sure about the syntax.

Any help would be much appreciated!

agents = new ArrayList<Capsule>(); // creating the agents

for (int i = 0; i < 85; i++) {
if (i < 20) agents.add(new MW1(random(width),random(height),color(255,0,0),i));
else if (i < 45) agents.add(new FW1(random(width),random(height),color(0,255,0),i));
else if (i < 65) agents.add(new MW2(random(width),random(height),color(155,0,0),i));
else agents.add(new FnW2(random(width),random(height),color(0,155,0),i));
}
}


//--------------configuring the canvas & the counter-------------


void draw() {
background(255);
time(); //reference to the visual timer


if(millis() - time >= wait){
println(counter);//if it is, do something
temp=counter;
time = millis();//also update the stored time
counter++; // counter augmentation

if(counter >180){ // check whether time exceeds 180 sec. aka 24:00 hours
counter=0; 
}
}

//-------------------------------------------------------------

work.Default(); //main-basic functions of (W) facility
retail.Default(); //main-basic functions of (R) facility
school.Default(); //main-basic functions of (S) facility
leisure.Default(); //main-basic functions of (L) facility

PVector vectorOfwork = new PVector(work.location.x, work.location.y); 
PVector vectorOfretail = new PVector(retail.location.x, work.location.y); 
PVector vectorOfschool = new PVector(school.location.x, school.location.y); 
PVector vectorOfleisure = new PVector(leisure.location.x, leisure.location.y); 

for( Capsule agent : agents) { // instancing - creating objects
agent.Default(); // global separation that affects ALL the agents
agent.separate(agents); // global separation that affects ALL the agents

if (counter>0 && counter<=30) {

if (agent instanceof FnW2)
agent.arrive(MW2.location); 
}
}
}
Community
  • 1
  • 1
  • Can you just post the relevant portions of code in your question? The URL has too many lines to read through. – Ravi Y Dec 09 '12 at 14:27
  • This is unlikely to get any answers. Try to come up with an example that other people can copy, paste, compile and get the same error you are getting. – n. m. could be an AI Dec 09 '12 at 17:17

0 Answers0