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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T15:26:04+00:00 2026-05-21T15:26:04+00:00

I am trying to acquire my location for an application I am working on.

  • 0

I am trying to acquire my location for an application I am working on. However I receive an error then force close when it tries to select the best provider. Any help on the issue would be much appreciated…do I need to declare something in onCreate in order for it to work? Here is a snippet of code followed by the error:

public void onStart(){
    super.onStart();
    locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
    Criteria criteria = new Criteria();
    best = locationManager.getBestProvider(criteria, true);//Selects best location provider given options between GPS and poor man's
    locationProvider = locationManager.getProvider(best);

        if (locationProvider != null) {
            locationManager.requestLocationUpdates(locationProvider.getName(), 60000, 1,
                this.locationListenerRecenterMap);
        } else {
            Log.e(TAG, "NO LOCATION PROVIDER AVAILABLE");
            Toast.makeText(this, "The GPS location provider is not available at this time.", Toast.LENGTH_SHORT).show();
            finish();
        }

    GeoPoint location = this.getLastKnownPoint();
    this.mapController.animateTo(location);
}
public void onResume(){
    super.onResume();
    locationManager.requestLocationUpdates(best, 15000, 1, (LocationListener) this);
}
public void onPause(){
    locationManager.removeUpdates((LocationListener) this);
}
private GeoPoint getLastKnownPoint(){
    GeoPoint lastKnownPoint = GeoUpdateHelper.SCRANTON;
    Location lastKnownLocation = this.locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    if(lastKnownLocation != null){
    lastKnownPoint = GeoUpdateHelper.getGeoPoint(lastKnownLocation);
    }else{
        lastKnownPoint = GeoUpdateHelper.SCRANTON;
    }
    return lastKnownPoint;
}

And here is the error:

04-16 19:07:25.077: ERROR/AndroidRuntime(4998): Caused by: java.lang.IllegalArgumentException: name==null
04-16 19:07:25.077: ERROR/AndroidRuntime(4998):     at android.location.LocationManager.getProvider(LocationManager.java:324)
04-16 19:07:25.077: ERROR/AndroidRuntime(4998):     at com.example.mapMain.onStart(mapMain.java:76)

EDIT: This is running on my OG Droid. When I click to open the map part of the application which gets the location it force closes.

  • 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-21T15:26:05+00:00Added an answer on May 21, 2026 at 3:26 pm

    The error indicates that no best provider was found, and the call to getBestProvider() returned null.

    Although you didn’t really specify any criteria, one would expect this call to at least return “something”. The javadocs are a bit vague, and don’t mention that this method can return null. (looking at the source code, it actually can return null)

    However, it is possible that your app / device doesn’t have any providers available.
    Can you execute the following call to check if it returns any providers (it will return all enabled providers, not taking into account any criteria) ?

    locationManager.getProviders(true) 
    

    Assuming this is a limitation of the application, double check if you have the following permissions defined, as they will be required to return some kind of provider.

    <uses-permission android:name="android.permission.INTERNET"/> 
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

All, I'm writing a native application for Android and i'm stuck trying to acquire
I am attempting to simply acquire the user's GPS location, but my application crashes
Trying to build out an exception if move.UserId does not equal currentUserId then Redirect
Trying to copy the msdn refernce here doesn't work and gives an error I
I am trying to acquire single images from a camera, do some processing to
I am creating an image processing application in C# and trying to take advantage
I am trying to send a location update with the new location as a
I am trying to aquire a wake lock however when I call PowerManager.newWakeLock() I
Background I'm trying to implement block file locking in my C# application. The built-in
I have lost many hours trying to grab exclusively the mouse in my application

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.