On Thu, May 5, 2011 at 2:20 PM, Prayag Pathak <prayag.d.pat...@gmail.com> wrote:
> I am trying to get the latitude and longitude of the current location.
> Let me clarify, I dont want to implement a listener that will create
> an event when the location will be changed.

You act as though you have a choice in the matter.

> I am trying to create an
> app that will record the current location on a button click event.
> Following is my code :
>
> hdLocMgr = (LocationManager)
> getSystemService(Context.LOCATION_SERVICE);
> Log.w("LocationTracker", "The Location Manager is :
> "+hdLocMgr.toString());
> hdLocProvider = hdLocMgr.getBestProvider(hdCrit, true);
> location = hdLocMgr.getLastKnownLocation(hdLocProvider);
> dlat = location.getLatitude();
> dlon = location.getLongitude();
> Log.w("LocationTracker", "The value of Latitude is :
> "+dlat.toString());
>
> The code gives a RunTimeException (caused by NullPointerException as
> stated in it).

Use adb logcat, DDMS, or the DDMS perspective in Eclipse to examine
LogCat and look at the stack trace to find the line that has the
NullPointerException. If I had to guess, your location variable is
null, because getLastKnownLocation() is null, because there is no
location for the provider, because you have not requested location
updates on that provider.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

_Android Programming Tutorials_ Version 3.4 Available!

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to