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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:09:04+00:00 2026-06-12T05:09:04+00:00

New to this, but I can’t see any problem. There’s a checkbox in settings

  • 0

New to this, but I can’t see any problem. There’s a checkbox in settings to start the Async task hence the if statement in onCreate. I just get a Java null error on the line where the task is executed.

Code

ProgressDialog progressDialog;
double longitude, latitude;
Location location;

private static final long MIN_DISTANCE_CHANGE_FOR_UPDATES = 10; // 10 meters


private static final long MIN_TIME_BW_UPDATES = 1000 * 60 * 1; // 1 minute


protected LocationManager locationManager;

GPSLocation task = new GPSLocation();

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_confirm_screen);
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
    Boolean locationCheck = sp.getBoolean("LOCATION", false);
  if(locationCheck){

        task.execute();
    }
   else
   {
    sendEmail();
    playSound();
   }

}

public double getLatitude()
{
    if (location != null)
    {
        latitude = location.getLatitude();
    }

    return latitude;
}

public double getLongitude()
{
    if (location !=  null)
    {
        longitude = location.getLongitude();
    }
    return longitude;
}

public class GPSLocation extends AsyncTask<Void, Void, Void> implements LocationListener
{  
    boolean running =true;
            @Override
            protected void onPreExecute()
            {  
                super.onPreExecute(); 
                progressDialog = new ProgressDialog(ConfirmScreen.this);
                progressDialog.setOnCancelListener(new DialogInterface.OnCancelListener(){
                      public void onCancel(DialogInterface dialog) {
                          //getgps.cancel(true);  
                      }
                });

                locationManager.requestLocationUpdates(
                        LocationManager.GPS_PROVIDER,
                        MIN_TIME_BW_UPDATES,
                        MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
                Log.d("GPS Enabled", "GPS Enabled");
                if (locationManager != null) {
                    location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
                            if (location != null) {
                                    latitude = location.getLatitude();
                                    longitude = location.getLongitude();  
                                    progressDialog.setCancelable(true);
                                    progressDialog.setMessage("Getting GPS Location...");
                                    progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                                    progressDialog.setProgress(1);
                                    progressDialog.show();
                            }
                }

            } 

            @Override 
            protected void onProgressUpdate(Void... values) {
                super.onProgressUpdate(values);
                // Things to be done while execution of long running operation is in progress. For example updating ProgessDialog
             }

            @Override 
            protected void onPostExecute(Void result)
            {  
                    progressDialog.cancel(); 
                    sendEmail("GPS: ", Double.toString(longitude).trim(), Double.toString(latitude).trim());
                    playSound();
            }

            @Override
            protected Void doInBackground(Void... params) {  
                boolean isDataSubmitted = false;

                while(!isDataSubmitted)
                {  
                    if(longitude !=0 && latitude!=0)
                    { 
                        sendEmail(); //Send Email without co-ords
                        playSound();
                        isDataSubmitted = true;  
                    }  
                } 

                return null;    
            }

            @Override
            public void onLocationChanged(Location location) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onProviderDisabled(String provider) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onProviderEnabled(String provider) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onStatusChanged(String provider, int status,
                    Bundle extras) {
                // TODO Auto-generated method stub

            } 
 } 


public void backHome(View view) 
{
    Intent intent = new Intent (this, MainScreen.class);
    startActivity(intent);
}

// Method to start playing and looping a sound.

public void playSound()
{
    MediaPlayer clickSound = MediaPlayer.create(this, R.raw.warning);
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
    Boolean soundCheck = sp.getBoolean("SOUND", false);
    if (soundCheck)
    {
        clickSound.start();
    }



}// method end

public void sendEmail()
{
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
    String nameValue = sp.getString("NAME", "failed to get name");
    String emailValue = sp.getString("EMAIL", "failed to get email");
    Intent i = new Intent(Intent.ACTION_SEND);
    i.setType("message/rfc822");
    i.putExtra(Intent.EXTRA_EMAIL, new String[]{emailValue});
    i.putExtra(Intent.EXTRA_SUBJECT, "Email sent from DON'T PANIC - A Chris O'Brien Project");
    i.putExtra(Intent.EXTRA_TEXT, "Hi there\n" + nameValue + " is in mortal danger. They didn't include co-ords as they assume you know where they are..\nKind Regards\nDon't Panic! \n\n\n");

    try
    {   startActivity(Intent.createChooser(i, "Send mail...."));
    } 
    catch (android.content.ActivityNotFoundException ex){

        Toast.makeText(ConfirmScreen.this, "There are no email clients installed or set up", Toast.LENGTH_SHORT).show();
    }
}


public void sendEmail(String a, String b, String c)
{
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
    String nameValue = sp.getString("NAME", "failed to get name");
    String emailValue = sp.getString("EMAIL", "failed to get email");
    Intent i = new Intent(Intent.ACTION_SEND);
    i.setType("message/rfc822");
    i.putExtra(Intent.EXTRA_EMAIL, new String[]{emailValue});
    i.putExtra(Intent.EXTRA_SUBJECT, "Email sent from DON'T PANIC - A Chris O'Brien Project");
    i.putExtra(Intent.EXTRA_TEXT, "Hi there\n" + nameValue + " is in mortal danger. Please see the co-ords attached and run to their rescue!" +
            " If you don't see any co-ords, they didn't check the box and assume you know where they are.\nKind Regards\nDon't Panic! \n\n\n" + 
            a + b + c);

    try
    {   startActivity(Intent.createChooser(i, "Send mail...."));
    } 
    catch (android.content.ActivityNotFoundException ex){

        Toast.makeText(ConfirmScreen.this, "There are no email clients installed or set up", Toast.LENGTH_SHORT).show();
    }
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_confirm_screen, menu);
    return true;
}






}

Debug Info

10-03 08:38:16.890: D/dalvikvm(27516): Late-enabling CheckJNI
10-03 08:38:16.990: I/dalvikvm(27516): Turning on JNI app bug workarounds for target SDK version 11...
10-03 08:38:17.030: E/Trace(27516): error opening trace file: No such file or directory (2)
10-03 08:38:17.600: D/dalvikvm(27516): GC_FOR_ALLOC freed 58K, 9% free 12206K/13315K, paused 105ms, total 111ms
10-03 08:38:17.610: I/dalvikvm-heap(27516): Grow heap (frag case) to 13.616MB for 784248-byte allocation
10-03 08:38:17.755: D/dalvikvm(27516): GC_CONCURRENT freed 1K, 8% free 12971K/14087K, paused 35ms+9ms, total 147ms
10-03 08:38:17.940: D/dalvikvm(27516): GC_FOR_ALLOC freed 0K, 8% free 12971K/14087K, paused 32ms, total 32ms
10-03 08:38:17.985: I/dalvikvm-heap(27516): Grow heap (frag case) to 16.606MB for 3136944-byte allocation
10-03 08:38:18.025: D/dalvikvm(27516): GC_CONCURRENT freed 0K, 7% free 16034K/17159K, paused 24ms+1ms, total 40ms
10-03 08:38:18.025: D/dalvikvm(27516): WAIT_FOR_CONCURRENT_GC blocked 4ms
10-03 08:39:44.110: E/SpannableStringBuilder(27516): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
10-03 08:39:44.110: E/SpannableStringBuilder(27516): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
10-03 08:39:45.145: E/SpannableStringBuilder(27516): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
10-03 08:39:45.145: E/SpannableStringBuilder(27516): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
10-03 08:39:45.910: D/dalvikvm(27516): GC_FOR_ALLOC freed 815K, 11% free 15718K/17543K, paused 9ms, total 9ms
10-03 08:39:45.910: I/dalvikvm-heap(27516): Grow heap (frag case) to 19.016MB for 2850872-byte allocation
10-03 08:39:45.925: D/dalvikvm(27516): GC_CONCURRENT freed 10K, 10% free 18492K/20359K, paused 1ms+1ms, total 12ms
10-03 08:39:45.955: D/dalvikvm(27516): GC_FOR_ALLOC freed 0K, 10% free 18492K/20359K, paused 9ms, total 9ms
10-03 08:39:45.970: I/dalvikvm-heap(27516): Grow heap (frag case) to 29.882MB for 11403440-byte allocation
10-03 08:39:45.990: D/dalvikvm(27516): GC_CONCURRENT freed 0K, 7% free 29628K/31559K, paused 11ms+2ms, total 22ms
10-03 08:39:46.025: D/AndroidRuntime(27516): Shutting down VM
10-03 08:39:46.025: W/dalvikvm(27516): threadid=1: thread exiting with uncaught exception (group=0x41d77300)
10-03 08:39:46.035: E/AndroidRuntime(27516): FATAL EXCEPTION: main
10-03 08:39:46.035: E/AndroidRuntime(27516): java.lang.RuntimeException: Unable to start activity ComponentInfo{cs4084.panic.button/cs4084.panic.button.ConfirmScreen}: java.lang.NullPointerException
10-03 08:39:46.035: E/AndroidRuntime(27516):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
10-03 08:39:46.035: E/AndroidRuntime(27516):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
10-03 08:39:46.035: E/AndroidRuntime(27516):    at android.app.ActivityThread.access$600(ActivityThread.java:140)
10-03 08:39:46.035: E/AndroidRuntime(27516):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
10-03 08:39:46.035: E/AndroidRuntime(27516):    at android.os.Handler.dispatchMessage(Handler.java:99)
10-03 08:39:46.035: E/AndroidRuntime(27516):    at android.os.Looper.loop(Looper.java:137)
10-03 08:39:46.035: E/AndroidRuntime(27516):    at android.app.ActivityThread.main(ActivityThread.java:4898)
10-03 08:39:46.035: E/AndroidRuntime(27516):    at java.lang.reflect.Method.invokeNative(Native Method)
10-03 08:39:46.035: E/AndroidRuntime(27516):    at java.lang.reflect.Method.invoke(Method.java:511)
10-03 08:39:46.035: E/AndroidRuntime(27516):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
10-03 08:39:46.035: E/AndroidRuntime(27516):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
10-03 08:39:46.035: E/AndroidRuntime(27516):    at dalvik.system.NativeStart.main(Native Method)
10-03 08:39:46.035: E/AndroidRuntime(27516): Caused by: java.lang.NullPointerException
10-03 08:39:46.035: E/AndroidRuntime(27516):    at cs4084.panic.button.ConfirmScreen$GPSLocation.onPreExecute(ConfirmScreen.java:89)
10-03 08:39:46.035: E/AndroidRuntime(27516):    at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)
10-03 08:39:46.035: E/AndroidRuntime(27516):    at android.os.AsyncTask.execute(AsyncTask.java:534)
10-03 08:39:46.035: E/AndroidRuntime(27516):    at cs4084.panic.button.ConfirmScreen.onCreate(ConfirmScreen.java:46)
10-03 08:39:46.035: E/AndroidRuntime(27516):    at android.app.Activity.performCreate(Activity.java:5184)
10-03 08:39:46.035: E/AndroidRuntime(27516):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)
10-03 08:39:46.035: E/AndroidRuntime(27516):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
10-03 08:39:46.035: E/AndroidRuntime(27516):    ... 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-06-12T05:09:05+00:00Added an answer on June 12, 2026 at 5:09 am

    I think you are getting a null pointer in onPreExecute method , so I guess locationManager is null , Try to initialize it as in onCreate() method.

    locationManager = (LocationManager) this
                .getSystemService(Context.LOCATION_SERVICE);
    

    Hope this solves the null error problem.

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

Sidebar

Related Questions

This can be done by making a new HTTP handler, but is there a
I am pretty new to Ubuntu, but I can't seem to get this to
im new at javascript and i can get this slider to work but not
I'm sure this is pretty elementary but I'm new to php. Can someone tell
Hi Guys new to this site but a big fan. Right the problem. It's
I am new to Emacs. I have googled this but no good answer there.
I'm new to posting on this forum but can't tell you how many times
I am new on django. I tried this but I can't deploy. How can
I'm new to parsing XML. I dug into this but can't find the answer.
hello i am little new to all this but i want to know that:

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.