SKRouteManager.getInstance().calculateRoute(route);在 SKMaps SDK 2.4 中返回空指针异常
Posted
技术标签:
【中文标题】SKRouteManager.getInstance().calculateRoute(route);在 SKMaps SDK 2.4 中返回空指针异常【英文标题】:SKRouteManager.getInstance().calculateRoute(route); return nullpointer exception in SKMaps SDK 2.4 【发布时间】:2015-05-02 20:12:32 【问题描述】:我能够初始化 SKMaps 并在我的 MapsActivity 中显示地图。 问题是我的应用程序在尝试计算路线时会因空指针异常而崩溃。
现在代码通过点击地图设置了 Advisorsettings,这仅用于测试目的,因为我想确保它在计算路线之前设置这些设置,通过双击启动也是测试目的。
我读到 Skobbler SDK 2.4 有这方面的问题,必须设置 advisorSettings 才能使其正常工作,但这对我没有帮助。
知道为什么 launchRouteCalculation() 会崩溃吗? 我应该直接恢复到 SDK 2.3 还是有修复方法?
澄清:SKRouteManager.getInstance().calculateRoute(route);让它崩溃。
public class MapsActivity extends Activity implements SKMapSurfaceListener, SKRouteListener
/**
* Surface view for displaying the map
*/
private SKMapSurfaceView mapView;
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
SKMapViewHolder mapHolder = (SKMapViewHolder)
findViewById(R.id.map_surface_holder);
mapView = mapHolder.getMapSurfaceView();
mapView.setMapSurfaceListener(this);
SKRouteManager.getInstance().setRouteListener(MapsActivity.this);
Toast.makeText(getApplicationContext(), "Loading Map...", Toast.LENGTH_SHORT).show();
mapView.getMapSettings().setCurrentPositionShown(true);
mapView.setZoom(20);
/*
Button navBtn = (Button)findViewById(R.id.navBtn);
navBtn.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View v)
Toast.makeText(getApplicationContext(), "You clicked the button...", Toast.LENGTH_SHORT).show();
);
*/
@Override
protected void onPause()
super.onPause();
mapView.onPause();
@Override
protected void onResume()
super.onResume();
mapView.onResume();
@Override
public void onActionPan()
@Override
public void onActionZoom()
@Override
public void onSurfaceCreated()
//System.out.print("Surface created");
Toast.makeText(getApplicationContext(), "Map loaded! Yeey!", Toast.LENGTH_SHORT).show();
@Override
public void onScreenOrientationChanged()
@Override
public void onMapRegionChanged(SKCoordinateRegion skCoordinateRegion)
@Override
public void onMapRegionChangeStarted(SKCoordinateRegion skCoordinateRegion)
@Override
public void onMapRegionChangeEnded(SKCoordinateRegion skCoordinateRegion)
@Override
public void onDoubleTap(SKScreenPoint skScreenPoint)
launchRouteCalculation();
@Override
public void onSingleTap(SKScreenPoint skScreenPoint)
String mapResDirPath;
File externalDir = getExternalFilesDir(null);
// determine path where map resources are
if (externalDir != null)
mapResDirPath = externalDir + "/SKMaps/";
else
mapResDirPath = getFilesDir() + "/SKMaps/";
final SKAdvisorSettings advisorSettings = new SKAdvisorSettings();
advisorSettings.setLanguage(SKAdvisorSettings.SKAdvisorLanguage.LANGUAGE_EN);
advisorSettings.setAdvisorConfigPath(mapResDirPath + "/SKMaps/Advisor/");
advisorSettings.setResourcePath(mapResDirPath + "/SKMaps/Advisor/Languages/");
advisorSettings.setAdvisorVoice("en");
advisorSettings.setAdvisorType(SKAdvisorSettings.SKAdvisorType.AUDIO_FILES);
SKRouteManager.getInstance().setAudioAdvisorSettings(advisorSettings);
Toast.makeText(getApplicationContext(),advisorSettings.getAdvisorVoice(), Toast.LENGTH_SHORT).show();
//Toast.makeText(getApplicationContext(), "You clicked the map! Yeey!", Toast.LENGTH_SHORT).show();
@Override
public void onRotateMap()
@Override
public void onLongPress(SKScreenPoint skScreenPoint)
@Override
public void onInternetConnectionNeeded()
@Override
public void onMapActionDown(SKScreenPoint skScreenPoint)
@Override
public void onMapActionUp(SKScreenPoint skScreenPoint)
@Override
public void onPOIClusterSelected(SKPOICluster skpoiCluster)
@Override
public void onMapPOISelected(SKMapPOI skMapPOI)
@Override
public void onAnnotationSelected(SKAnnotation skAnnotation)
@Override
public void onCustomPOISelected(SKMapCustomPOI skMapCustomPOI)
@Override
public void onCompassSelected()
@Override
public void onCurrentPositionSelected()
@Override
public void onObjectSelected(int i)
@Override
public void onInternationalisationCalled(int i)
@Override
public void onBoundingBoxImageRendered(int i)
@Override
public void onGLInitializationError(String s)
public void launchRouteCalculation()
// get a route settings object and populate it with the desired properties
SKRouteSettings route = new SKRouteSettings();
// set start and destination points
route.setStartCoordinate(new SKCoordinate(57.708266, 11.935341));
route.setDestinationCoordinate(new SKCoordinate(57.715098, 11.945383));
// set the number of routes to be calculated
route.setNoOfRoutes(1);
// set the route mode
route.setRouteMode(SKRouteSettings.SKRouteMode.CAR_FASTEST);
// set whether the route should be shown on the map after it's computed
route.setRouteExposed(true);
// set the route listener to be notified of route calculation
// events
SKRouteManager.getInstance().setRouteListener(this);
// pass the route to the calculation routine
SKRouteManager.getInstance().calculateRoute(route);
@Override
public void onRouteCalculationCompleted(SKRouteInfo skRouteInfo)
@Override
public void onRouteCalculationFailed(SKRoutingErrorCode skRoutingErrorCode)
@Override
public void onAllRoutesCompleted()
@Override
public void onServerLikeRouteCalculationCompleted(SKRouteJsonAnswer skRouteJsonAnswer)
@Override
public void onOnlineRouteComputationHanging(int i)
【问题讨论】:
【参考方案1】:对于 2.4,解决方法是使用 SKRouteManager.getInstance().getAdviceList()。设置 advisorSettings 并让 SKMaps.zip 中的 Advisor 文件夹(带有所需的配置文件)。 在 2.5 中,您将可以删除 advisorSettings 并且应用不会再崩溃。
【讨论】:
以上是关于SKRouteManager.getInstance().calculateRoute(route);在 SKMaps SDK 2.4 中返回空指针异常的主要内容,如果未能解决你的问题,请参考以下文章