title: Printing the output of command to text area/text panel - JSch
body: <p>The program is part of JSch which previously use to reads the output content and then print it to console, But I have made UI which has textPanel and I want to write the extracted content to the text area. But I am getting Null pointer exception. There is something wrong the way I am calling the textPanel.  </p>
  
  <p>JumpHosts - <a href="http://www.jcraft.com/jsch/examples/JumpHosts.java.html" rel="nofollow">http://www.jcraft.com/jsch/examples/JumpHosts.java.html</a> (For Full Program)</p>
  
  <pre><code>            byte[] tmp = new byte[1024];
              while (true) {
                  while (in.available() &gt; 0) {
                      int i = in.read(tmp, 0, 1024);
                      if (i &lt; 0)
                          break;
                      //System.out.print(new String(tmp, 0, i));
                      textPanel.appendText(new String(tmp, 0, i));
                  }
                  if (channel.isClosed()) {
                      //System.out.println("exit-status: " + channel.getExitStatus());
                      textPanel.appendText(new String("exit-status: " + channel.getExitStatus()));
                      break;
                  }
                  try {
                      Thread.sleep(1000);
                  } catch (Exception ee) {
                      System.out.println(ee);
                  }
              }`
  </code></pre>
  
  <p>Text Panel Code here :</p>
  
  <pre><code>public class TextPanel extends JPanel {
  
  private JTextArea textArea;
  
  public TextPanel(){
  
      setLayout(new BorderLayout());
  
      textArea = new JTextArea();
  
      add(new JScrollPane(textArea),BorderLayout.CENTER);
  }
  
  public void appendText(String tmp){
  
      textArea.append(tmp);
  
  }
  </code></pre>
  
  <p>Text Panel is Initialized in MainFrame class :</p>
  
  <pre><code>public class MainFrame extends JFrame{
  
  private TextPanel textPanel;
  private Toolbars toolbar;
  private FormPanel formPanel;;
  
  public MainFrame() {
  
      super("ABC");
  
      setLayout(new BorderLayout());
  
      //setJMenuBar(createMenuBar());
  
      textPanel = new TextPanel();
      toolbar = new Toolbars();
      formPanel = new FormPanel();
  
      toolbar.setStringListener(new StringListeners() {
          public void textEmitter(String text) {
              textPanel.appendText(text);
          }
      });
  
      formPanel.setFormListener(new FormListener(){
          public void formEventOccured(FormEvent e){
              String name = e.getName();
              String occupation = e.getOccupation();
  
              textPanel.appendText(name + " : " + occupation + "\n");
  
          }       
      });
  
      add(textPanel,BorderLayout.CENTER);
      add(toolbar,BorderLayout.NORTH);
      add(formPanel,BorderLayout.WEST);
  
      setVisible(true);
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      setMinimumSize(new Dimension(500, 400));
      setSize(600, 500);
  
  }
  </code></pre>