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);
}