Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

"cannot make static reference to non-static field"

807601May 20 2008 — edited May 22 2008
Hi, I was trying to keep a counter variable that would increment separately for each instance of my cube class every time the constructor from the face class is called within the cube constructor, but Java doesn't seem to like my implementation. Any ideas? I know I could do this manually, but I'm looking for an way to automatically increment. The essentials of my code should look something like this... note that I am showing two separate classes. Thanks in advance for any advice!


public class face{

private int[] data;

public face (String name){
this.name = name;
data = new int[3];

for (int i = 0; i<3; i++){
data = i + (3**cube.counter*-1);
}
cube.counter++;
}
}



public class cube{

private face front, back, side;
public int counter = 1;

public cube() {
front = new face("Front");
back = new face("Back");
side = new face("Side");
}

}


Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 19 2008
Added on May 20 2008
17 comments
501 views