-1
当编译下面的代码,我得到的编译错误:如何防止GPS更新?
Error:(154, 47) error: local variable locationListener is accessed from within inner class; needs to be declared final
论locationListener
以下行:
getDistance(locationA,locationListener);
lm.removeUpdates(locationListener);
如何防止GPS的更新?
locationListener = new LocationListener() {
@Override
public void onLocationChanged(final Location location) {
Location net_loc, gps_loc;
net_loc = location;
while (net_loc != null) {
showCurrentLocation(net_loc);
Location locationA = new Location("A");
locationA.setLatitude(location.getLatitude());
locationA.setLongitude(location.getLongitude());
getDistance(locationA,locationListener);
lm.removeUpdates(locationListener);
}
要么声明'locationListener'' final',要么将其声明移至类范围。 –
我这样做,但它永远不会停止GPS更新 –
[你之前没有搜索问](http://stackoverflow.com/search?q= [爪哇] +%22is +访问+从+内+内+类%3B + need + to + be +%+%22 + is%3Aquestions + answers%3A1)28个答案至今为止。 –