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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:40:42+00:00 2026-06-09T05:40:42+00:00

Hey While I am running the application it gives a error java.lang.IllegalArgumentException: listener==null ,

  • 0

Hey While I am running the application it gives a error java.lang.IllegalArgumentException: listener==null , that tells that listener is null.

My sample code is here:

public class HelloAndroidGpsActivity extends Activity {
private EditText editTextShowLocation;
private Button buttonGetLocation;
private LocationManager locManager;
private LocationListener locListener;
private Location mobileLocation;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    editTextShowLocation = (EditText) findViewById(R.id.editTextShowLocation);
    buttonGetLocation = (Button) findViewById(R.id.buttonGetLocation);  
    buttonGetLocation.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            buttonGetLocationClick();
        }
    });
}

/** Gets the current location and update the mobileLocation variable*/
private void getCurrentLocation() {
    locManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
    System.out.println("mobile location manager is ="+locManager);
    locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locListener);
    locListener = new LocationListener() {  
        @Override
        public void onStatusChanged(String provider, int status,
                Bundle extras) {
            System.out.println("mobile location is in listener1");
        }
        @Override
        public void onProviderEnabled(String provider) {
            System.out.println("mobile location is in listener2");
        }
        @Override
        public void onProviderDisabled(String provider) {
            System.out.println("mobile location is in listener3");
        }
        @Override
        public void onLocationChanged(Location location) {
            System.out.println("mobile location is in listener="+location);
            mobileLocation = location;
        }
    };
    System.out.println("after setting listener");
}
private void buttonGetLocationClick() {
    getCurrentLocation(); 
    System.out.println("mobile location is ="+mobileLocation);  
    if (mobileLocation != null) {
        locManager.removeUpdates(locListener); 
        String londitude = "Londitude: " + mobileLocation.getLongitude();
        String latitude = "Latitude: " + mobileLocation.getLatitude();
        String altitiude = "Altitiude: " + mobileLocation.getAltitude();
        String accuracy = "Accuracy: " + mobileLocation.getAccuracy();
        String time = "Time: " + mobileLocation.getTime();
        editTextShowLocation.setText(londitude + "\n" + latitude + "\n"
                + altitiude + "\n" + accuracy + "\n" + time);
    } else {
        editTextShowLocation.setText("Sorry, location is not determined");
    }
}
}

Output in textbox is “Sorry, location is not determined””
If any one can tell me what is the problem then please help me.
Thank you

  • 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-09T05:40:43+00:00Added an answer on June 9, 2026 at 5:40 am

    Initialize the listener before you use it.

    locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locListener);
    

    At this point of time, locListener is null, and you are initializing it after this line of code. This may be the reason.

    So rearrange the lines of your code like this;

       locListener = new LocationListener() {...};
       locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locListener);
    

    Hope this may help to solve your issue…

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

Sidebar

Related Questions

Hey all. I've been looking for a while for something that can help me
Hey guys I'm running this code in Android: public ServiceServer(String serverName) { this.serverName =
Hey fellas, while running through a debugger I am seeing the following appear the
Hey everybody, I am writing a program that compares the running times of various
Hey, while programming stuff, I have found that it is often very helpful to
Hey math geeks, I've got a problem that's been stumping me for a while
Hey I am getting following error while try to deploy my project on remote
Hey dudes.i am having this problem while symlinking. I have successfully deployed a ruby
Hey I am having some issues while using Nggalley plugin for wordpress the plugin
Hey so I've been dealing with this issue for a while. So, part of

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.