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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:42:58+00:00 2026-05-27T20:42:58+00:00

In my Main class I call another class to do something, and I need

  • 0

In my Main class I call another class to do something, and I need to return the data back to the Main class but it’s crashing for some reason on startup of the application:

My Main Activity – it crashes in getLocation() something to do with returning the Location and assigning to a Point, because when I take these lines out, it works fine.

public class Main extends Activity {

    ArrayList<Point> gpsCoordinates = new ArrayList<Point>();

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.pages);
        vf = (ViewFlipper) findViewById(R.id.viewFlipper);

        try {
            getLocation(null);
        } catch (InterruptedException e) {}

    }

public synchronized void getLocation(View view) throws InterruptedException
    {

        LocationHandler lh = new LocationHandler();
        lh.getLocation(view,this);
        Location location = new Location(lh.returnLocation());
        Point point = new Point(location.getLongitude(),location.getLatitude());
        gpsCoordinates.add(point);
    } 
}

My Point class:

public class Point {

    private double x;
    private double y;

    public Point(double x, double y) {
        this.setX(x);
        this.setY(y);
    }

    public Point(Point point) {
        this.setX(point.getX());
        this.setY(point.getY());
    }

    public String toString(Point point)
    {
        String stringPoint = "";
        stringPoint = "(" + point.getX() + "," + point.getY() + ")";
        return stringPoint;
    }

    public void setX(double x2) {
        this.x = x2;
    }

    public double getX() {
        return this.x;
    }

    public void setY(double y2) {
        this.y = y2;
    }

    public double getY() {
        return this.y;
    }
}

Class I’m calling from Main:

public class LocationHandler {
    Location location;
    public synchronized void getLocation(final View view, final Main main) throws InterruptedException
    {   

        Thread t = new Thread(){
            public synchronized void run(){

                location = new Location(mlocListener.returnLocation());


            }

        };
        t.start();

    } 

    public Location returnLocation()
    {   
        return location;

    }

}

Error log:

12-20 12:35:11.348: E/AndroidRuntime(3466): FATAL EXCEPTION: main
12-20 12:35:11.348: E/AndroidRuntime(3466): java.lang.RuntimeException: Unable to start activity ComponentInfo{mfc.generalgui6api8/mfc.generalgui6api8.Main}: java.lang.NullPointerException
12-20 12:35:11.348: E/AndroidRuntime(3466):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
12-20 12:35:11.348: E/AndroidRuntime(3466):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
12-20 12:35:11.348: E/AndroidRuntime(3466):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
12-20 12:35:11.348: E/AndroidRuntime(3466):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
12-20 12:35:11.348: E/AndroidRuntime(3466):     at android.os.Handler.dispatchMessage(Handler.java:99)
12-20 12:35:11.348: E/AndroidRuntime(3466):     at android.os.Looper.loop(Looper.java:123)
12-20 12:35:11.348: E/AndroidRuntime(3466):     at android.app.ActivityThread.main(ActivityThread.java:4627)
12-20 12:35:11.348: E/AndroidRuntime(3466):     at java.lang.reflect.Method.invokeNative(Native Method)
12-20 12:35:11.348: E/AndroidRuntime(3466):     at java.lang.reflect.Method.invoke(Method.java:521)
12-20 12:35:11.348: E/AndroidRuntime(3466):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
12-20 12:35:11.348: E/AndroidRuntime(3466):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
12-20 12:35:11.348: E/AndroidRuntime(3466):     at dalvik.system.NativeStart.main(Native Method)
12-20 12:35:11.348: E/AndroidRuntime(3466): Caused by: java.lang.NullPointerException
12-20 12:35:11.348: E/AndroidRuntime(3466):     at android.location.Location.set(Location.java:123)
12-20 12:35:11.348: E/AndroidRuntime(3466):     at android.location.Location.<init>(Location.java:116)
12-20 12:35:11.348: E/AndroidRuntime(3466):     at mfc.generalgui6api8.Main.getLocation(Main.java:133)
12-20 12:35:11.348: E/AndroidRuntime(3466):     at mfc.generalgui6api8.Main.onCreate(Main.java:44)
12-20 12:35:11.348: E/AndroidRuntime(3466):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-20 12:35:11.348: E/AndroidRuntime(3466):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
12-20 12:35:11.348: E/AndroidRuntime(3466):     ... 11 more
  • 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-27T20:42:59+00:00Added an answer on May 27, 2026 at 8:42 pm

    I ended up using:

    How to declare global variables in Android?

    This allowed me to save the GPS location straight when it had retrieved it in the LocationListener

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

Sidebar

Related Questions

I need help trying to call a class function within another class. Here's my
I have two classes which extend Activity and need to call another class method
I have a main class in a program that launches another class that handles
I am trying to run a function of the main class, but even with
I have a class with several constructors and I want to call the main
I have an application, which does smth... at the begining of main class I
How can I call a subclass out of another subclass, if the first class
I have a small Java test app in Netbeans where the main() class reads
I subclassed UIScrollView Then created an object of it in the main class. Added
I'm creating a website with structure like this: class main { } class mysql

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.