Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8519023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:08:07+00:00 2026-06-11T06:08:07+00:00

I have a getter setter class named SharedData.java . I am getting null pointer

  • 0

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 :

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;
}

}

Here is my code :

       SharedData sharedData ;  
       sharedData = SharedData.getInstance();
       sharedData.setSrc_latitude(latitude);
   sharedData.setEnd_longitude(longitude);

Can anybody please help me with this ? Thanks .

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T06:08:08+00:00Added an answer on June 11, 2026 at 6:08 am

    You never initialized sharedData, so its value is null, calling a method on it got your program to crash.

    I think you’re trying to use Singleton Pattern. Try the below:

    private static SharedData instance = new SharedData();   \\ Initialize here
    
    private SharedData() {        // Make it private....
        // 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;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a class: class MyClass { @Getter @Setter int a; @Getter @Setter int
I have a Class that has a private variable with a public setter/getter function:
I have a class defined like this, with the appropriate getter and setter methods...
I have the following classes... class ExpressionBinder<T> { public Func<T> Getter; public Action<T> Setter;
If a class contains a variable named blah, then the standard getter/setter syntax is
The getter and setter class is becoming NULL when i try to fetch values
I have a class with a property called title and I have a getter/setter
For example, I have a class with a public field and corresponding getter/setters: public
I have two domain classes (getter setter of two tables): Contact Information and Address
I have a string array selectCancel with setter and getter methods, which is a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.