title: Exception in thread "thread-4" java.lang.NullPointerException
body: <p>I'd really appreciate some help with my program</p>
  
  <pre><code>    Exception in thread "Thread-4" java.lang.NullPointerException
      at ServerConnect.replyChoice(BaseStaInstance.java:63)
      at ServerConnect.run(BaseStaInstance.java:45)
      at java.lang.Thread.run(Thread.java:619)
  </code></pre>
  
  <p>my ServerConnect function looks like :-</p>
  
  <pre><code>class ServerConnect extends Thread {
  
   Socket skt;
   String sProcessId;
   ServerConnect scnt = null; 
   ObjectOutputStream myOutput;
   ObjectInputStream myInput;
  
  
   ServerConnect(){}
   ServerConnect(Socket connection, String sProcessNo) {
    this.skt = connection;
    this.sProcessId = sProcessNo;
   }
  
   public void run() {
    try {
     myInput = new ObjectInputStream(skt.getInputStream());
     ServerConnect scnt = new ServerConnect();
  
     while(true) {
      try{
       int ownTimeStamp = Global.iTimeStamp;
  
       Object buf = myInput.readObject();
  
       //if we got input, print it out and write a message back to the remote client...
       if(buf != null){
   LINE 45--&gt;     **scnt.replyChoice(buf);**
  
       }
  
      }catch(ClassNotFoundException e) {
       e.printStackTrace();
      }
     }
    } catch(IOException e) {
     e.printStackTrace();
    }
   }
  
   void replyChoice(Object buf){
  
  
    try{
  LINE 63 --&gt; **myOutput = new ObjectOutputStream(skt.getOutputStream());**
  
  
    System.out.println("Server read:[ "+buf+" ]");
    myOutput.writeObject("got it");
    myOutput.flush();
  
    }catch(IOException e){
    e.printStackTrace();
    }
   }
  }
  </code></pre>
  
  <p>Its basically a socket programming and multithreaded application. On executing it on different terminals inorder to have the client and server establish connections, I execute my code. But it throws up the error above on both terminals. Its just got something to do with my declaring the myOutput variable at the wrong place. Could someone help me out.
  From the error message, I've highlighted line 63 and line 45 in the piece of code attached.</p>