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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:56:27+00:00 2026-06-17T10:56:27+00:00

I want to use a constructor that calls a method points() . This method

  • 0

I want to use a constructor that calls a method points() . This method calculates the latitude and longitude of 3 points. I need those values in another class. Hence I am trying to call the method in the constructor.
Please help me with the syntax for this.

This is my class FirstActivity

package com.example.gpsdistance;

import android.os.Bundle;
import android.os.Handler;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

public class FirstActivity extends Activity {

    Button btnShowLocation, btnMinDis;
    TextView display= null;
    public float check= 5; 

    //private final Context mctx;
    double latuser;
    double longuser;
    double dx1, dy1, delta_long1, delta_lat1, final_long1, final_lat1;
    double dx2, dy2, delta_long2, delta_lat2, final_long2, final_lat2;
    double dx3, dy3, delta_long3, delta_lat3, final_long3, final_lat3;
    public float latA, longA, latB, longB, latC, longC, lati1;
    // GPSTracker class
    GPSTracker gps;


    void points()
    {
        latuser = gps.getLatitude();
        longuser = gps.getLongitude();

        dx1 = 120*Math.cos(35); 
        dy1 = 120*Math.sin(35); 
        delta_long1 = dx1/(111320*Math.cos(latuser));   
        delta_lat1 = dy1/110540;   
        final_long1 = longuser + delta_long1;
        final_lat1 = latuser + delta_lat1;
        dx2 = 150*Math.cos(38); 
        dy2 = 150*Math.sin(38); 
        delta_long2 = dx2/(111320*Math.cos(latuser));   
        delta_lat2 = dy2/110540;   
        final_long2 = longuser + delta_long2;
        final_lat2 = latuser + delta_lat2;
        dx3 = 180*Math.cos(38); 
        dy3 = 180*Math.sin(38); 
        delta_long3 = dx3/(111320*Math.cos(latuser));   
        delta_lat3 = dy3/110540;   
        final_long3 = longuser + delta_long3;
        final_lat3 = latuser + delta_lat3;

        latA= (float)final_lat1;
        longA= (float)final_long1;
        latB= (float)final_lat2;
        longB= (float)final_long2;
        latC= (float)final_lat3;
        longC= (float)final_long3;
    }

    private float computeDistance(double lat1, double lon1,
            double lat2, double lon2) {
            // Based on http://www.ngs.noaa.gov/PUBS_LIB/inverse.pdf
            // using the "Inverse Formula" (section 4)

            int MAXITERS = 20;
            // Convert lat/long to radians
            lat1 *= Math.PI / 180.0;
            lat2 *= Math.PI / 180.0;
            lon1 *= Math.PI / 180.0;
            lon2 *= Math.PI / 180.0;

            double a = 6378137.0; // WGS84 major axis
            double b = 6356752.3142; // WGS84 semi-major axis
            double f = (a - b) / a;
            double aSqMinusBSqOverBSq = (a * a - b * b) / (b * b);

            double L = lon2 - lon1;
            double A = 0.0;
            double U1 = Math.atan((1.0 - f) * Math.tan(lat1));
            double U2 = Math.atan((1.0 - f) * Math.tan(lat2));

            double cosU1 = Math.cos(U1);
            double cosU2 = Math.cos(U2);
            double sinU1 = Math.sin(U1);
            double sinU2 = Math.sin(U2);
            double cosU1cosU2 = cosU1 * cosU2;
            double sinU1sinU2 = sinU1 * sinU2;

            double sigma = 0.0;
            double deltaSigma = 0.0;
            double cosSqAlpha = 0.0;
            double cos2SM = 0.0;
            double cosSigma = 0.0;
            double sinSigma = 0.0;
            double cosLambda = 0.0;
            double sinLambda = 0.0;

            double lambda = L; // initial guess
            for (int iter = 0; iter < MAXITERS; iter++) {
                double lambdaOrig = lambda;
                cosLambda = Math.cos(lambda);
                sinLambda = Math.sin(lambda);
                double t1 = cosU2 * sinLambda;
                double t2 = cosU1 * sinU2 - sinU1 * cosU2 * cosLambda;
                double sinSqSigma = t1 * t1 + t2 * t2; // (14)
                sinSigma = Math.sqrt(sinSqSigma);
                cosSigma = sinU1sinU2 + cosU1cosU2 * cosLambda; // (15)
                sigma = Math.atan2(sinSigma, cosSigma); // (16)
                double sinAlpha = (sinSigma == 0) ? 0.0 :
                    cosU1cosU2 * sinLambda / sinSigma; // (17)
                cosSqAlpha = 1.0 - sinAlpha * sinAlpha;
                cos2SM = (cosSqAlpha == 0) ? 0.0 :
                    cosSigma - 2.0 * sinU1sinU2 / cosSqAlpha; // (18)

                double uSquared = cosSqAlpha * aSqMinusBSqOverBSq; // defn
                A = 1 + (uSquared / 16384.0) * // (3)
                    (4096.0 + uSquared *
                     (-768 + uSquared * (320.0 - 175.0 * uSquared)));
                double B = (uSquared / 1024.0) * // (4)
                    (256.0 + uSquared *
                     (-128.0 + uSquared * (74.0 - 47.0 * uSquared)));
                double C = (f / 16.0) *
                    cosSqAlpha *
                    (4.0 + f * (4.0 - 3.0 * cosSqAlpha)); // (10)
                double cos2SMSq = cos2SM * cos2SM;
                deltaSigma = B * sinSigma * // (6)
                    (cos2SM + (B / 4.0) *
                     (cosSigma * (-1.0 + 2.0 * cos2SMSq) -
                      (B / 6.0) * cos2SM *
                      (-3.0 + 4.0 * sinSigma * sinSigma) *
                      (-3.0 + 4.0 * cos2SMSq)));

                lambda = L +
                    (1.0 - C) * f * sinAlpha *
                    (sigma + C * sinSigma *
                     (cos2SM + C * cosSigma *
                      (-1.0 + 2.0 * cos2SM * cos2SM))); // (11)

                double delta = (lambda - lambdaOrig) / lambda;
                if (Math.abs(delta) < 1.0e-12) {
                    break;
                }
            }

            float distance = (float) (b * A * (sigma - deltaSigma));

            return distance;
    }

    FirstActivity()
        {

            points();
        }


    @Override
    protected void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.firstactivity);
            final LinearLayout lView = new LinearLayout(this);  
            display= new TextView(this);
            btnMinDis=new Button(this);
            btnMinDis.setText("Nearest Point");
            final Handler mHandler = new Handler();
            btnShowLocation = (Button) findViewById(R.id.buttonLocation);

            btnShowLocation.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) 
                {
                    // TODO Auto-generated method stub

                    // create class object
                    gps = new GPSTracker(FirstActivity.this);

                    // check if GPS enabled
                    if(gps.canGetLocation())
                        {
                        points();
                            float initialdisA = computeDistance( latuser, longuser, latA, longA);
                            float initialdisB = computeDistance( latuser, longuser, latB, longB);
                            float initialdisC = computeDistance( latuser, longuser, latC, longC);         
                            Toast.makeText(getApplicationContext(),"\nLatitude: " + latA ,  Toast.LENGTH_LONG).show();
                            lView.addView(display);
                            setContentView(lView);
                            display.setText("Initial Location is - \nLatitude: " + latuser + " N" + "\nLongitude: " + longuser + " E"
                                        + "\n\n\nPoint A:\n" + "Latitude: " + latA + "N" + "\nLongitude: " + longA + "E" 
                                        + "\nPoint B:\n" + "Latitude: " + latB + "N" + "\nLongitude: " + longB + "E" 
                                        + "\nPoint C:\n" + "Latitude: " + latC + "N" + "\nLongitude: " + longC + "E"
                                        + "\n\n\nInitial Distance A: " + initialdisA + "m" + "\nInitial Distance B: " + initialdisB + "m" + "\nInitial Distance C: " + initialdisC + "m");


                            mHandler.postDelayed(mLaunchTask,10000);
                        }
                    else
                        {
                    // GPS or Network is not enabled
                    // Ask user to enable GPS/network in settings
                    gps.showSettingsAlert();
                        }   
              }  

            private Runnable mLaunchTask = new Runnable() 
            {
                public void run() 
                {
                    Intent i = new Intent(getApplicationContext(),NearestPoint.class);
                    startActivity(i);
                }
            };    
         });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.firstactivity, menu);
        return true;
    }

}

I tried using these:

1)

FirstActivity()
{
    points();
}

2)

FirstActivity(Context context)
{
this.mContext = context;
  points();
}

I am getting error with both: “Application stopped working…”

Here’s my logcat:

01-19 10:12:40.488: D/dalvikvm(608): newInstance failed: Lcom/example/gpsdistance/FirstActivity;.<init>() not accessible to Landroid/app/Instrumentation;
01-19 10:12:40.538: D/AndroidRuntime(608): Shutting down VM
01-19 10:12:40.578: W/dalvikvm(608): threadid=1: thread exiting with uncaught exception (group=0x40015560)
01-19 10:12:40.688: E/AndroidRuntime(608): FATAL EXCEPTION: main
01-19 10:12:40.688: E/AndroidRuntime(608): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.gpsdistance/com.example.gpsdistance.FirstActivity}: java.lang.IllegalAccessException: access to constructor not allowed
01-19 10:12:40.688: E/AndroidRuntime(608):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
01-19 10:12:40.688: E/AndroidRuntime(608):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
01-19 10:12:40.688: E/AndroidRuntime(608):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
01-19 10:12:40.688: E/AndroidRuntime(608):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
01-19 10:12:40.688: E/AndroidRuntime(608):  at android.os.Handler.dispatchMessage(Handler.java:99)
01-19 10:12:40.688: E/AndroidRuntime(608):  at android.os.Looper.loop(Looper.java:123)
01-19 10:12:40.688: E/AndroidRuntime(608):  at android.app.ActivityThread.main(ActivityThread.java:3683)
01-19 10:12:40.688: E/AndroidRuntime(608):  at java.lang.reflect.Method.invokeNative(Native Method)
01-19 10:12:40.688: E/AndroidRuntime(608):  at java.lang.reflect.Method.invoke(Method.java:507)
01-19 10:12:40.688: E/AndroidRuntime(608):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
01-19 10:12:40.688: E/AndroidRuntime(608):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-19 10:12:40.688: E/AndroidRuntime(608):  at dalvik.system.NativeStart.main(Native Method)
01-19 10:12:40.688: E/AndroidRuntime(608): Caused by: java.lang.IllegalAccessException: access to constructor not allowed
01-19 10:12:40.688: E/AndroidRuntime(608):  at java.lang.Class.newInstanceImpl(Native Method)
01-19 10:12:40.688: E/AndroidRuntime(608):  at java.lang.Class.newInstance(Class.java:1409)
01-19 10:12:40.688: E/AndroidRuntime(608):  at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
01-19 10:12:40.688: E/AndroidRuntime(608):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
01-19 10:12:40.688: E/AndroidRuntime(608):  ... 11 more
01-19 10:12:43.669: I/Process(608): Sending signal. PID: 608 SIG: 9
  • 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-17T10:56:28+00:00Added an answer on June 17, 2026 at 10:56 am

    Your points function contains this call

    latuser = gps.getLatitude();

    However, the gps variable is not initialized yet. The creation of the gps object is made only later and ONLY if the user presses a button you add to the activity in the onCreate event.

    Create the gps earlier… eg in points()

    or create a function that you will use throughout the class instead of plain call of gps.

    function  getGPS() {
      if (gps == null)
        gps = new GPSTracker(FirstActivity.this);
      return gps;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Perl, if I want to use named parameters in an object constructor, my
I want to use the DbProvider class to construct a generic DAL component. This
I want use this 1 for using Bar code or QR code scanner. I
I want use jQuery in my project. I know the javascript_include_tag calls the jQuery
I have created a repository class that I want to use in a code
Is it possible to call an abstract constructor in one method, then pass that
I have a category class that I want to Use that acts on a
I want use BYTE_ORDER macro in my Xcode project but i can't because i
I want use javascript setInterval function to achieve a box rotate animate effect, I
I want use a single php file to handle all of my voting requests.

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.