I'll preface this by saying that I've been a longtime fan of Stack Overflow, and over the past few semesters I've usually been able to find the answer to all my questions without actually asking one. However, I've been having problems with a stack program. There's more code than this, but I think I've narrowed my problem down to this one error. It states
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Cannot make a static reference to the non-static field Stack1
The constructor Stack(int) is undefinedat stack.main(stack.java:11)
Can anyone explain what the issue might be? Or better yet, point me to somewhere that will explain it? I've tried looking it up on Overflow and through google, but I think a combination of not knowing what I'm actually looking for and/or fatigue is preventing me from finding a concrete answer. Thanks for any help in advance.
public class stack {
private Object[] Stack1;
private int topOfStack;
private int max;
//private int empty;
//private int capacity;
public static void main(String[] args) {
Stack1 = new Stack(5);
}
public Stack(int size) {
if (size < 0){
throw new IllegalArgumentException("Parameter must be >0. Parameter was " + size + ".");
}
max = size;
Stack1 = (Object[]) (new Object[size]);
topOfStack = -1;
}
}