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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T16:52:14+00:00 2026-05-19T16:52:14+00:00

I am trying to geolocate a lat,long pair. When there is no exception it

  • 0

I am trying to geolocate a lat,long pair. When there is no exception it works great.

Logcat:

GLS Failed With Status 20

The code follows:

//TAG GEOCODING METHOD
    public Address getAddressForLocation(Context context, Location location) throws IOException {

     Address a = null;
     try{
        if (location == null) {
            a=null;
        }
        double latitude = location.getLatitude();
        double longitude = location.getLongitude();
        int maxResults = 1;


        Geocoder gc = new Geocoder(context, Locale.getDefault());
        List<Address> addresses = gc.getFromLocation(latitude, longitude, maxResults);


        if (addresses.size() == 1) {
            a=addresses.get(0);
        } else {
            a=null;
        }
     }catch (Exception e){
      Log.w("EXCEPTON!", "Exception Caught in geocode");
      a=null;
     }
     return a;
    }

The call is also wrapped in a try/catch block.

 @Override//TAG On Location Changed
    public void onLocationChanged(Location arg0) {
//SET ALL VALUES
            dlat = arg0.getLatitude();
            dlon = arg0.getLongitude();

            delev = arg0.getAltitude() * 3.2808399;
            delev = round(delev, 2);

//GET THE ADDRESS
              try {
                addy = getAddressForLocation(this,arg0);
               } catch (Exception e) {
                 // TODO Auto-generated catch block
                 e.printStackTrace();
                }
                _lastaddy = _addy;
                //DISPLAY ALL INFORMATION
                 _addy = addy.getAddressLine(0);  
                    LONGBOX.setText(String.valueOf(dlon));
                   LATBOX.setText(String.valueOf(dlat));
if(_addy!=_lastaddy){
                      ADDRESS.setText(_addy);
}

                  }

The rest of the logcat is below. Any help with this would be GREAT. I can not catch this exception and have stared at this code so long and still dont know what I have done wrong.

LOGCAT:

LocationMasfClient  reverseGeocode(): GLS failed with status 20
AndroidRuntime      Shutting down VM
dalvikvm            threadid=1: thread exiting with uncaught exception (group=0x400208b0)
AndroidRunTime      FATAL EXCEPTION: main
AndroidRunTime      java.lang.NullPointerException
  • 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-19T16:52:15+00:00Added an answer on May 19, 2026 at 4:52 pm

    I think the problem is that you catch the exception, but then return (and eventually try to use) a null Address object in getAddressForLocation

    catch (Exception e){
          Log.w("EXCEPTON!", "Exception Caught in geocode");
          a=null;
         }
         return a;
    

    So, at this point addy will be null:

    addy = getAddressForLocation(this,arg0);
    

    When you go to use addy, you will get a NullPointerException

    _addy = addy.getAddressLine(0);  
    

    You either need to check if addy is null before you use it, or throw the Exception you catch in getAddressForLocation and handle it in onLocationChange

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

Sidebar

Related Questions

Trying to get comfortable with jQuery and I have encountered some sample code that
Trying to figure out why my vertex shader works on my cell phone (Casio
Trying to understand how EDE works by using it to generate Makefiles for a
Trying to launch and pass tel. no. to skype by this code from my
Trying to anonymize received headers for relayed messages from authenticated postfix users, there is
Trying to set RowHeight like this(in code): dgvTruckAvail.RowTemplate.Height = 48; Doesnt' work. I also
Trying to make this function dynamic instead of static. This was the original code
Trying to comply with StackOverflow's suggestion of asking a question, not creating a discussion,
Trying to use this method (gist of which is use self.method_name in the FunnyHelper
Trying to get parameters from a PUT request using HttpServlet#doPut: public void doPut(HttpServletRequest request,

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.