3 Replies Latest reply: Apr 9, 2008 6:49 PM by 807591 RSS

    passing string Class to Class

    807591
      Hi im getting a nullpointerexception with the following
      private EditorGUI gui;
      /////
      ....
      gui.sysOut("hello world");
      .....
      /////
      public void sysOut(String msg) {
              output.append(msg + "\n");
          }
      thanks

      steve
        • 1. Re: passing string Class to Class
          JoachimSauer
          Where did you set gui to a valid value? Where is the code gui.sysOut()? Are you sure that gui is already correctly initialized at that point?
          • 2. Re: passing string Class to Class
            807591
            thanks for your quick reply...

            basically there is the maingui... i press button1... i get a new frame (gui),

            I want it to send a string back saying "loading"... the maingui has a output JTextArea... that is like a mini system out and reports actions... like file saved correctly etc.

            thanks
            • 3. Re: passing string Class to Class
              807591
              Could you post the stacktrace? And indicate which lines of your code it is referring to?

              If the NPE occured with "gui.sysOut("hello world")" - and not the output.append() line - then gui is null. You can check this using System.out.prinltn():
              System.out.println("gui=" + gui);
              gui.sysOut("hello world");
              And, in that case, the question you asked about where gui was initialised is a good one: you need to examine your code at that point and figure out why gui didn't get a value, or got a value but was subsequently set to null.