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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:48:18+00:00 2026-06-15T11:48:18+00:00

I’m working on an app where users need to give their latitude and longitude

  • 0

I’m working on an app where users need to give their latitude and longitude location in order to post any information. The problem is when I use the following code:

/********************************************************************
* GET LATITUDE                                                      *
********************************************************************/
public String getLatitude(){
    LocationManager lm = (LocationManager) ACTIVITY.getSystemService(Context.LOCATION_SERVICE); 

    if( lm.isProviderEnabled( LocationManager.GPS_PROVIDER )){
        Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
        if(location != null){
            return Double.toString( location.getLatitude() );
        }
    }
    return null;
}


/********************************************************************
* GET LONGITUDE                                                     *
********************************************************************/
public String getLongitude(){
    LocationManager lm = (LocationManager) ACTIVITY.getSystemService(Context.LOCATION_SERVICE); 

    if( lm.isProviderEnabled( LocationManager.GPS_PROVIDER )){
        Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
        if(location != null){
            return Double.toString( location.getLongitude() );
        }
    }
    return null;
}

I get to see the following error messages:

12-06 22:31:46.791: W/dalvikvm(1173): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
12-06 22:31:46.811: E/AndroidRuntime(1173): FATAL EXCEPTION: main
12-06 22:31:46.811: E/AndroidRuntime(1173): java.lang.IllegalStateException: Could not execute method of the activity
12-06 22:31:46.811: E/AndroidRuntime(1173):     at android.view.View$1.onClick(View.java:3044)
12-06 22:31:46.811: E/AndroidRuntime(1173):     at android.view.View.performClick(View.java:3511)
12-06 22:31:46.811: E/AndroidRuntime(1173):     at android.view.View$PerformClick.run(View.java:14105)
12-06 22:31:46.811: E/AndroidRuntime(1173):     at android.os.Handler.handleCallback(Handler.java:605)
12-06 22:31:46.811: E/AndroidRuntime(1173):     at android.os.Handler.dispatchMessage(Handler.java:92)
12-06 22:31:46.811: E/AndroidRuntime(1173):     at android.os.Looper.loop(Looper.java:137)
12-06 22:31:46.811: E/AndroidRuntime(1173):     at android.app.ActivityThread.main(ActivityThread.java:4424)
12-06 22:31:46.811: E/AndroidRuntime(1173):     at java.lang.reflect.Method.invokeNative(Native Method)
12-06 22:31:46.811: E/AndroidRuntime(1173):     at java.lang.reflect.Method.invoke(Method.java:511)
12-06 22:31:46.811: E/AndroidRuntime(1173):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
12-06 22:31:46.811: E/AndroidRuntime(1173):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
12-06 22:31:46.811: E/AndroidRuntime(1173):     at dalvik.system.NativeStart.main(Native Method)
12-06 22:31:46.811: E/AndroidRuntime(1173): Caused by: java.lang.reflect.InvocationTargetException
12-06 22:31:46.811: E/AndroidRuntime(1173):     at java.lang.reflect.Method.invokeNative(Native Method)
12-06 22:31:46.811: E/AndroidRuntime(1173):     at java.lang.reflect.Method.invoke(Method.java:511)
12-06 22:31:46.811: E/AndroidRuntime(1173):     at android.view.View$1.onClick(View.java:3039)
12-06 22:31:46.811: E/AndroidRuntime(1173):     ... 11 more
12-06 22:31:46.811: E/AndroidRuntime(1173): Caused by: java.lang.NullPointerException
12-06 22:31:46.811: E/AndroidRuntime(1173):     at com.example.cay.saati.Helper.getLatitude(Helper.java:100)
12-06 22:31:46.811: E/AndroidRuntime(1173):     at com.example.cay.saati.MenuPage.prepareLoginInformation(MenuPage.java:230)
12-06 22:31:46.811: E/AndroidRuntime(1173):     at  com.example.cay.saati.MenuPage.onClick(MenuPage.java:267)
12-06 22:31:46.811: E/AndroidRuntime(1173):     ... 14 more

I use the following permissions to use LocationManager:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

And also library:

<uses-library android:name="com.google.android.maps" />

Can someone tell me what the exact problem is? What does cause java.lang.reflect.invocationTargetException? I don’t get it. Thanks!

  • 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-15T11:48:22+00:00Added an answer on June 15, 2026 at 11:48 am

    lastKnownLocation can return null.

    gps works using an observer design pattern – you request it to give you a location , and using a listener , it will call the relevant function by itself , giving you the location it has found .

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

Sidebar

Related Questions

Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
link Im having trouble converting the html entites into html characters, (&# 8217;) i
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I've tracked down a weird MySQL problem to the two different ways I was
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have been unable to fix a problem with Java Unicode and encoding. The
I need a function that will clean a strings' special characters. I do NOT
I have thousands of HTML files to process using Groovy/Java and I need to

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.