![](/img/trans.png)
[英]Getting Null Pointer Exception with setCenter() method in JavaFX with Scene Builder 8.0
[英]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);得到空響應。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.