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

  • Home
  • SEARCH
  • 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 6240569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:35:36+00:00 2026-05-24T11:35:36+00:00

I have two classes and I want to pass a (geo-point) variable on touch

  • 0

I have two classes and I want to pass a (geo-point) variable on touch from one to the other, so that I can calculate the distance between user current location and the geo-point.

Long story short:

My first class is named Session and the second Calculation – they are in the same package.

I declare the variables as public in the main class. On touch, I save the users current location into the (public) geo-point variable called userposition.

Then in the second class I use

Session pass = new Session();

to create an instance of the Session. After which I try to retrieve the userposition variable:

Geopoint position = pass.userposition;

But it keeps returning null and throws exception even if I tested the variable on the main class and works great … What am I missing here??

The main code for Session is:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.maps);
    // Blah blah blah

    // And here i declare the GestureDetector...I working with google maps.
    Gest = new GestureDetector(new SimpleOnGestureListener());

    mapView.getOverlays().add(new Overlay() {
        @Override
        public boolean onTouchEvent(MotionEvent e, MapView mapView) {
            Gest.onTouchEvent(e);
            return super.onTouchEvent(e, mapView);
        }
    });

    Gest.setOnDoubleTapListener(new OnDoubleTapListener() {

        @Override
        public boolean onDoubleTap(MotionEvent e) {
            // and in here i set the variable which works fine i tested it
            // in a textView
            userposition = myLocationOverlay.getMyLocation();
        }
    });
}

And for my Calculation class:

public Overlays(Drawable defaultMarker, Context context) {
    super(boundCenterBottom(defaultMarker));
    mContext = context;
}

public void addOverlay(OverlayItem overlay) {
    mOverlays.add(overlay);
    populate();
}

@Override
protected OverlayItem createItem(int i) {
    // TODO Auto-generated method stub
    return mOverlays.get(i);
}

@Override
public int size() {
    // TODO Auto-generated method stub
    return mOverlays.size();
}

@Override
public boolean onTap(int index) {
    // and here i try to get the variable by taping a marker on map (its a
    // lot of code no need to post works fine too)

    Session pass = new Session();
    Geopoint position = pass.userposition;
}

And then I get the null pointer exception.

What I noticed (I’m not so good at Java so I will try to explain) is that I can pass a variable like an integer (I tried it) from the main class Session. The thing is that to pass the geo-point, I need to pass the variable into the Gesture Detection onDoubleTap method inside the Session … something like pass.onDoubleTap.userposition because that is the variable I need, and in that class the variable is not null. But how I go about doing that??

  • 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-24T11:35:37+00:00Added an answer on May 24, 2026 at 11:35 am

    I solved it by declaring the variable static, so that it can be shared across all classes in the package.

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

Sidebar

Related Questions

I have a couple of classes that want to pass each other some information
I have two classes, and want to include a static instance of one class
I have two classes that each need an instance of each other to function.
I have two classes and want to build a collection that contains a collection.
I have two classes, Foo and Bar, that have constructors like this: class Foo
Let's say that I have two classes A and B. class A { private:
I have two C# classes that have many of the same properties (by name
Let just say that we have two classes, A and B . Here is
I have two similar classes, that simply have a string name. I wanted to
I have two classes: Media and Container. I have two lists List<Media> and List<Container>

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.