Location object passed into onLocationChanged is null?

和自甴很熟 提交于 2019-12-02 10:39:34

I have fixed the problem, though I'm not sure why this worked.

What I did is I set my activity to request location updates from the best location provider (in this case the GPS) and set it to trigger my function onces it has a location accurate down to 50 meters. What I was doing before was just attempting to retrieve the last known location, but now I have it set to wait until the GPS can get a fix.

Perhaps it wasn't storing my last known location and thus was returning null.

I recommend you run this app using the debugger to find the cause of the null pointer. If the block of code that gets the location is in a try block you can add a breakpoint in the catch and the exception will give you a good idea what the cause is (and how to handle it).

Srinivas Kumar

I figured it out at last . there;s no problem what so ever in the code .

JUST SIMPLY RUN AN APPLICATION THAT WOULD STORE THE LATITUDE AND LONGITUDE DETAILS ...SAY LIKE YOUR MAPS BUILT IN APPLICATION IN YOUR MOBILE AND THEN RUN IT IT WOULD WORK FINE...

the reason why it gives a null is your phone would have stored the last known details and stack for it would be empty hence it pass a null . Running an app similar to maps or so would place in the location details in the stack and would fetch them back .. cheeers! @srinivas

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!