3 Replies Latest reply on Apr 9, 2008 11:49 PM by 807591

    passing string Class to Class

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

        • 1. Re: passing string Class to Class
          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
            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.

            • 3. Re: passing string Class to Class
              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.