English 中文(简体)
法定提及非统计领域 Java错误
原标题:Static reference to non-static field Java error

我要说的是,我早就是一个长时期的Stack Overflow的狂热,过去几秒钟,我通常能够找到回答我所有问题的办法,而实际上却不问问题。 然而,我早就在 st方案方面遇到问题。 但我认为我把问题缩小到了这个错误。 它指出:

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 undefined

页: 1

谁能解释问题是什么? 更糟糕的是,我会向某些地方提出解释? 我曾尝试过从多流量和直观的角度来审视这个问题,但我认为,如果我不知道我实际上在寻找什么和(或)疲劳,我就无法找到具体答案。 事先得到任何帮助。

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;
}
   }
最佳回答

重新命名“标准”(续)类,并改变行文:

Stack1 = new Stack(5)

:

Stack stack1 = new Stack(5);
问题回答

在以下各行:

private Object[] Stack1;

<>Stack1不是static

在座各位试图提及<代码>。 Stack1 -

public static void main(String[] args) {
    Stack1 = new Stack(5);
}

www.un.org/spanish/ga/president

因此,

不能静态提及非静态领域Stack1

页: 1 因此

构造者Stack(int)没有定义

请您在上查阅。 以下各段:

public static void main(String[] args) {
    Stack stack1 = new Stack(5);
}

页: 1

保持较低的案件类别申报,我猜测转让

   Stack1 = new Stack(5);

不是你所说的。 相反:

Stack1 stack = new stack(5);

<代码>Stack1在stack上可互换。 班级。 在你静态的主要方法中,你试图在<编码>Stack1变量中储存一个数值,尽管这是一个例子变量。 另外,你试图将非通知型号转让给其类型为array的<代码>。 此外,尽管在较低级别上称“stack,但您还是设有“>的构件(注上)。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签