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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:36:20+00:00 2026-05-22T14:36:20+00:00

When I try LocationProvider locationProvider = LocationManager.GPS_PROVIDER; IntelliJ is giving me an error: incompatible

  • 0

When I try LocationProvider locationProvider = LocationManager.GPS_PROVIDER; IntelliJ is giving me an error: incompatible types: required: android.location.LocationProvider found: java.lang.String.

What gives?

  • 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-22T14:36:21+00:00Added an answer on May 22, 2026 at 2:36 pm

    I have a project built in IDEA and haven’t had this problem. Have you checked you are importing all the appropriate packages?

    import android.location.Criteria;
    import android.location.Location;
    import android.location.LocationListener;
    import android.location.LocationManager;
    import android.location.GpsStatus;
    

    When you rightclick/Go To/Declaration LocationManager you should see the following code:

    package android.location;
    
    public class LocationManager  {
        public static final java.lang.String NETWORK_PROVIDER = "network";
        public static final java.lang.String GPS_PROVIDER = "gps";
    

    Update

    Ok. I know what is going on here. What you are doing is assigning a LocationManager.GPS_PROVIDER (which is actually a string) to a LocationProvider object. hence the incompatible types error.

    Is there a reason you want to instantiate a LocationProvider object? Looking at the LocationManager API, you don’t actually need one of these. The API takes the constant strings (GPS_PROVIDER, NETWORK_PROVIDER etc) and instantiates the appropriate LocationProvider internally. If you really need the LocationProvider instance, you can get it back from the LocationManager with the getProvider method.

    Another Update

    So it looks like the reason the OP encounted this problem in the first place is that the sample code on the Obtaining User Location documentation is just wrong:

    LocationProvider locationProvider = LocationManager.NETWORK_PROVIDER;
    // Or use LocationManager.GPS_PROVIDER
    
    Location lastKnownLocation = locationManager.getLastKnownLocation(locationProvider);
    

    LocationProvider is an abstract superclass and you shouldn’t be instantiating these things directly. Instead you pass a LocationManager.type_of_provider_here into the LocationManager and it instantiates an object that implements that abstract class. So the sample should be:

    Location lastKnownLocation = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

try: return [ True, errors[error], error ] # Error found except SoapFault as e:
Try this code - import java.io.StringReader; public class StringReaderTest { public static void main(String[]
try: html = urlopen('http://glbse.com/api/asset/' + asset.name) except: print 'error while updating the price of
in my application i try to fetch users location but it always 0.0 for
I can't read location with this function. When I try to get location information,
I try to add a location from the GPS but i always get null.
Try loading this normal .jpg file in Internet Explorer 6.0. I get an error
i make a location application on android. here's the code for acquiring lat and
Try this in chrome versus firefox/IE: var cancelPressed = false; function redirect() { //window.location
try { //String location = dir1.getCanonicalPath()+\\app_yamb_test1\\mySound.au; //displayMessage(location); AudioInputStream audio2 = AudioSystem.getAudioInputStream(getClass().getResourceAsStream(mySound.au)); Clip clip2 =

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.