-1

Thanks for taking your time to help me.

I have a problem with the "non-static ..." error and I don't know why. Here's the code

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

(This is just a part of the code. I know this ends while paraphrasing)

And the other class:

public class Server2 extends JFrame implements Runnable {
    konsol = new JTextPane();
    konsol.setEditable(false);

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

    public void run() {
        instance = new Server2();
        instance.setVisible(true);
    }
}

Again, this is also just a part of the code. I would really appreciate your help :)

Rumid
  • 1,627
  • 2
  • 21
  • 39
Bassusour
  • 175
  • 6
  • 14

1 Answers1

1

make this method as static

public static void setTekst(String tekst){
    konsol.setText(tekst);
}
SpringLearner
  • 13,738
  • 20
  • 78
  • 116
  • this is correct @SpringLearner i think the OP should make a lot of changes i hope you can make your post a **community wiki** so we can explain more – Youcef LAIDANI Mar 17 '17 at 10:11
  • @SpringLearner I already tried that, and am met with the exact same error. This time it is the following code that gives the error. konsol.setText(tekst); – Bassusour Mar 17 '17 at 10:18
  • @Bassusour show the line number where you are geting error – SpringLearner Mar 17 '17 at 10:22
  • @SpringLearner I edited the comment above with the location where i get the error, but I'll do it in a new comment aswell. I get it in the konsol.setText(tekst); – Bassusour Mar 17 '17 at 10:30
  • @Bassusour may be konsol is non static – SpringLearner Mar 17 '17 at 10:32
  • @SpringLearner thanks for the help, now i dont get that error :) However, i ran into a new problem. The text wont show up. I think I will make a new thread for this, after i give it a try myself – Bassusour Mar 17 '17 at 10:46