其他分享
首页 > 其他分享> > android-Maps API在animateTo()方法上引发NullPointerException

android-Maps API在animateTo()方法上引发NullPointerException

作者:互联网

尝试将地图动画化为某个GeoPoint时出现致命异常-这是例外:

12-20 17:53:20.400: E/Crittercism(3523): java.lang.NullPointerException
12-20 17:53:20.400: E/Crittercism(3523): at com.amazon.geo.maps.MercatorProjection.latLongToWorldPixels(MercatorProjection.java:397)
12-20 17:53:20.400: E/Crittercism(3523): at com.amazon.geo.maps.MercatorProjection.toPixels(MercatorProjection.java:69)
12-20 17:53:20.400: E/Crittercism(3523): at com.amazon.geo.maps.MapView.animateTo_AmazonInternal(MapView.java:1801)
12-20 17:53:20.400: E/Crittercism(3523): at com.amazon.geo.maps.MapController.animateTo(MapController.java:46)
12-20 17:53:20.400: E/Crittercism(3523): at com.fatattitude.myapplication.MyMapActivity.moveMapToPoint(BusMapActivity.java:1564)

这是我的代码.我的日志输出还显示GeoPoint的值为LatitudeE6 = 51537141和LongitudeE6 = -246271

private void moveMapToPoint(GeoPoint gp, int zoomLevel) {
MapController mc = mapView.getController();

if (zoomLevel < 0)
zoomLevel = mapView.getZoomLevel();

mc.stopAnimation(true);
mc.setZoom(zoomLevel);

String strGeoPointInfo = String.format("Lat:%d, Lng:%d", gp.getLatitudeE6(), gp.getLongitudeE6() );
Log.i("GeoPoint-Info", "**moveMapToPoint: " + strTestOutput);

mc.animateTo(gp);
}

如果我评论这行

//mc.stopAnimation(true);

我不再例外.

谁能帮助我了解为什么发生此异常?

请帮我.

解决方法:

该应用可能会等待GPS传感器寻找位置之前.

mMyLocationOverlay.runOnFirstFix(new Runnable() { 
    public void run() {
                    mapView.getController().animateTo(myLocation);
        }});                         

标签:android-maps,android-maps-v2,android-debug,android
来源: https://codeday.me/bug/20191031/1975323.html