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 6014591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:42:50+00:00 2026-05-23T02:42:50+00:00

So I had a question on here the other day about how to accessing

  • 0

So I had a question on here the other day about how to accessing the same data class with two different other classes without creating separate instances. It was recommended to use a singleton so i have done some research but there isn’t a lot about it.

The issue I’m having is that my main class gets a null pointer exception when trying to access the data singleton. But my other class can access it and get the data just fine. How exactly is that possible? I have a pretty basic setup…

singleton

public enum laneData {
    INSTANCE;
    private String laneID;

    public String getLaneID() {
        return laneID;
    }

    public void setLaneID(String laneID) {
        this.laneID = laneID;
    }

}

main class call

 private laneData laneData;
 public void init() {
     laneData.setLaneID("test"); //these two lines each throw null pointer unless commented out
     System.out.println(laneData.getLaneID()); 
     ....

other class

public class XMLParser {
private LaneGUI laneGUI;
private laneData laneData;


public void parseInputString(String input){ 
laneData.setLaneID(getCharacterDataFromElement(line));  //both of these work fine
System.out.println("stored ID: " + laneData.getLaneID());
  • 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-05-23T02:42:51+00:00Added an answer on May 23, 2026 at 2:42 am

    You need private laneData laneData = laneData.INSTANCE;.

    You can also just use laneData.INSTANCE.getLaneID().

    Java guidelines also recommend than Class and Enum names be capitalized, I.E. LaneData.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I had a question about Java Class Path variables. If I have multiple jars
The other question (here: ) had solutions that I tried but they didn't work.
Someone asked me a question via e-mail about integer partitions the other day (as
So, I had a question earlier about mod_rewrite which you find here mod_rewrite changing
I've attempted the question different ways, check my profile for the other two questions
I had a similar question answered Here There is a slight twist to the
Here is a question that I have had for some time but never actually
I read about Big-O Notation from here and had few questions on calculating the
Here's a few questions I had on a quiz in a class and just
I've had a few questions about MEF recently, but here's the big one --

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.