title: Read a message in Server from Client RMI
body: <p>I have a the necessary RMI classes created, The client can send a message and it gets printed in the server window.</p>
  
  <p>On the server i would like to read the message and for example if the message is equal to 100 then print out a message. </p>
  
  <p>The problem being when i run the server i immediately get a null pointer exception. When i send the message 100 from the client to the server it prints the message but wont execute the if statement.</p>
  
  <p>Interface:</p>
  
  <pre><code>import java.rmi.Remote;
  import java.rmi.RemoteException;
  
  public interface FileInterface extends Remote {
  
      void message(String message) throws RemoteException;
  
  }
  </code></pre>
  
  <p>Implementation:</p>
  
  <pre><code>import java.io.*;
  import java.rmi.*;
  import java.rmi.server.UnicastRemoteObject;
  
  public class FileImpl extends UnicastRemoteObject implements FileInterface  {
  
  private String name;
  
      public FileImpl(String s) throws RemoteException {
          super();
          name = s;
      }
  
      public void message(String message) throws RemoteException{
      System.out.println(message);
    }
  
        } catch(Exception e) {
           System.err.println("FileServer exception: "+ e.getMessage());
           e.printStackTrace();
           return(null);
        }
     }
  } 
  </code></pre>
  
  <p>Client:</p>
  
  <pre><code>import java.io.*; 
  import java.rmi.*;
  import javax.swing.*;
  import java.util.*;
  import java.awt.*;
  
  public class FileClient{
  
      public static boolean loggedIn = false;
  
     public static void main(String argv[]) {
        try {
  
          int RMIPort;         
          String hostName;
          InputStreamReader is = new InputStreamReader(System.in);
          BufferedReader br = new BufferedReader(is);
          System.out.println("Enter the RMIRegistry host namer:");
          hostName = br.readLine();
          if( hostName.length() == 0 ) // if user did not enter a name
                  hostName = "localhost"; // use the default host name
          System.out.println("Enter the RMIregistry port number:");
          String portNum = br.readLine();
          if( portNum.length() == 0 ) 
                  portNum = "1097"; // default port number
          RMIPort = Integer.parseInt(portNum);
          String registryURL = "rmi://" + hostName+ ":" + portNum + "/FileServer";  
          // find the remote object and cast it to an interface object
          FileInterface fi = (FileInterface) Naming.lookup(registryURL);
          System.out.println("Lookup completed " );
          //System.out.println("File " + argv[0] + " Transfered" );
          // invoke the remote method
          boolean done = false;
           //file.getName()
  
  
  
          while( !done ) {
  
              System.out.println("Enter Code: 100 = Login, 200 = Upload, 300 = Download, 400 = Logout: ");
              String message = br.readLine();
              boolean messageOK = false;
  
              if( message.equals("100") ) {
                  messageOK = true;
                  System.out.println("Enter T-Number: (Use Uppercase 'T')");
                  String login = br.readLine();
                  if( login.charAt(0) == 'T' ) {
                      loggedIn = true;
                      fi.message("100");
                      System.out.println("Login Successful");
                      continue;
                  } else {
                      System.out.println("Login Error");
                      continue;
                  }
              }
  
          }
      } catch (Exception ex) {
              ex.printStackTrace();
          } 
      }
  }
  </code></pre>
  
  <p>Server:</p>
  
  <pre><code>import java.io.*;
  import java.rmi.*;
  
  public class FileServer {
  
     public static void main(String argv[]) {
  
        if(System.getSecurityManager() == null) {
           System.setSecurityManager(new RMISecurityManager());
        }
        try {
           FileInterface fi = new FileImpl("FileServer");
           Naming.rebind("//localhost:1097/FileServer", fi);
           System.out.println("Server Started...");
  
          boolean done = false;
          while( !done ) {
  
          if ((msg.trim()).equals("100")) {
  
              System.out.println("message recieved: 100 logged in");
  
           } else {
              System.out.println("Login Error");
           }  
  
          }
  
        } catch(Exception e) {
           System.out.println("FileServer: "+e.getMessage());
           e.printStackTrace();
        }
     }
  }
  </code></pre>
  
  <p>Any help here would be appreciated.</p>