title: Null pointer exception on getter setter in java
body: <p>I have a getter setter class named SharedData.java . I am getting null pointer exception when I'm going to imply it on my code . Here is the SharedData class :</p>
  
  <pre><code>public class SharedData {
  private static SharedData instance = null;
  
  public SharedData() {
      // randomizeServers();
  }
  
  // data to be shared
  private double src_latitude = -1;
  private double src_longitude = -1;
  private double end_latitude = -1;
  private double end_longitude = -1;
  
  //Getter-Setters
  public static SharedData getInstance() {
      return instance;
  }
  public static void setInstance(SharedData instance) {
      SharedData.instance = instance;
  }
  
  public double getSrc_latitude() {
      return src_latitude;
  }
  public void setSrc_latitude(double src_latitude) {
      this.src_latitude = src_latitude;
  }
  public double getSrc_longitude() {
      return src_longitude;
  }
  public void setSrc_longitude(double src_longitude) {
      this.src_longitude = src_longitude;
  }
  public double getEnd_latitude() {
      return end_latitude;
  }
  public void setEnd_latitude(double end_latitude) {
      this.end_latitude = end_latitude;
  }
  public double getEnd_longitude() {
      return end_longitude;
  }
  public void setEnd_longitude(double end_longitude) {
      this.end_longitude = end_longitude;
  }
  
  }
  </code></pre>
  
  <p>Here is  my code :</p>
  
  <pre><code>       SharedData sharedData ;  
         sharedData = SharedData.getInstance();
         sharedData.setSrc_latitude(latitude);
     sharedData.setEnd_longitude(longitude);
  </code></pre>
  
  <p>Can anybody please help me with this ? Thanks .</p>