Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java &引用;非静态变量不能从静态上下文引用此变量;错误_Java_Compiler Errors_Non Static - Fatal编程技术网

Java &引用;非静态变量不能从静态上下文引用此变量;错误

Java &引用;非静态变量不能从静态上下文引用此变量;错误,java,compiler-errors,non-static,Java,Compiler Errors,Non Static,谢谢你花时间帮助我 我有一个“非静态…”错误的问题,我不知道为什么。这是密码 public class Klient { public static String output = "test"; public static void main(String[] args) throws Exception { Socket socket = new Socket("localhost", 9898); PrintStream PS = new P

谢谢你花时间帮助我

我有一个“非静态…”错误的问题,我不知道为什么。这是密码

public class Klient {
    public static String output = "test";
    public static void main(String[] args) throws Exception {
        Socket socket = new Socket("localhost", 9898);
        PrintStream PS = new PrintStream(socket.getOutputStream());

        InputStreamReader IR = new InputStreamReader(socket.getInputStream());
        BufferedReader BR = new BufferedReader(IR);

        int i;
        for (i = 0; i < 3; i++) {
            output = BR.readLine();
            Server2.setTekst(output);
        }

同样,这也是代码的一部分。非常感谢您的帮助:)

将此方法设置为静态

public static void setTekst(String tekst){
    konsol.setText(tekst);
}

这是正确的@SpringLearner我认为OP应该做很多改变我希望你能把你的帖子变成一个社区维基,这样我们就可以解释了more@SpringLearner我已经试过了,但遇到了完全相同的错误。这一次是下面的代码给出了错误。konsol.setText(tekst)@Bassusour显示您要到达的线路号error@SpringLearner我编辑了上面的评论和我得到错误的位置,但我也会在新的评论中这样做。我在konsol.setText(tekst)中得到它@Bassusour可能是konsol是非静态的
public static void setTekst(String tekst){
    konsol.setText(tekst);
}