簡體   English   中英

在Android中使用MapController的setCenter方法時出現空指針異常

[英]Null pointer exception while using the setCenter method of a MapController in Android

我正在使用此代碼設置地圖的中心。

mapController.setCenter(new GeoPoint((int)(location.getLatitude()*1E6), (int) (location.getLongitude()*1E6)));

位置定義為

locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();

criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
criteria.setCostAllowed(true);

provider = locationManager.getBestProvider(criteria, true);

Location location = locationManager.getLastKnownLocation(provider);

我收到此代碼的空指針異常。 我究竟做錯了什么?

如果提供程序當前被禁用,則返回null。

您可能會從locationManager.getLastKnownLocation(provider);得到空響應。

http://developer.android.com/reference/android/location/LocationManager.html#getLastKnownLocation%28java.lang.String%29

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM