PDA

View Full Version : [Android] SKRouteManager calculateRoute NullPointerException



marbampi
10.04.2015, 22:14
Hello,

I was following the "HowTo" tutorial for Android SDK and everything was working fine until I came across a NullPointerException while executing the launchRouteCalculation method shown in:

http://developer.skobbler.com/getting-started/android#sec012

I can't figure out what is giving me the exception. Here is the stack trace:

04-10 16:43:13.633 3590-3590/com.example.radiante.myapplication E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.radiante.myapplication, PID: 3590
java.lang.NullPointerException
at com.skobbler.ngx.routing.SKRouteManager.calculateR oute(SourceFile:212)
at com.example.radiante.myapplication.SkobblerActivit y.launchRouteCalculation(SkobblerActivity.java:422 )
at com.example.radiante.myapplication.SkobblerActivit y.onSurfaceCreated(SkobblerActivity.java:282)
at com.skobbler.ngx.map.MapRenderer$7.run(SourceFile: 669)
at android.os.Handler.handleCallback(Handler.java:733 )
at android.os.Handler.dispatchMessage(Handler.java:95 )
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.jav a:5356)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCa ller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit .java:1081)
at dalvik.system.NativeStart.main(Native Method)

The route calculation works fine when I'm using the DemoApp.

dandronic
11.04.2015, 08:18
Can you please also add the code you use to set up & call calculate route?

marbampi
13.04.2015, 15:12
Everything is done in the following activity:

public class SkobblerActivity extends Activity implements SKPrepareMapTextureListener, SKMapSurfaceListener, SKRouteListener {

private String mapResDirPath;
private ProgressDialog progressDialog;
private SKMapSurfaceView mapView;
private SKMapViewHolder mapHolder;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

File externalDir = getExternalFilesDir(null);
if (externalDir != null) {
mapResDirPath = externalDir + "/SKMaps/";
} else {
mapResDirPath = getFilesDir() + "/SKMaps/";
}

final SKPrepareMapTextureThread prepThread = new SKPrepareMapTextureThread(this, mapResDirPath, "SKMaps.zip", this);
prepThread.start();
}


@Override
public void onMapTexturesPrepared(boolean b) {
SKMapsInitSettings initMapSettings = new SKMapsInitSettings();
initMapSettings.setMapResourcesPaths(mapResDirPath , new SKMapViewStyle(mapResDirPath + "/outdoorstyle/", "outdoorstyle.json"));
initMapSettings.setPreinstalledMapsPath(mapResDirP ath + "/PreinstalledMaps");
SKMaps.getInstance().initializeSKMaps(this, initMapSettings, Constants.API_KEY);

setContentView(R.layout.activity_skobbler);
progressDialog = new ProgressDialog(this);
progressDialog.setMessage("Carregando mapa...");
progressDialog.setCancelable(false);
progressDialog.show();

getWindow().addFlags(WindowManager.LayoutParams.FL AG_KEEP_SCREEN_ON);

mapHolder = (SKMapViewHolder) findViewById(R.id.map_surface_holder);
mapView = mapHolder.getMapSurfaceView();
mapView.setMapSurfaceListener(this);

mapView.onResume();
}

@Override
public void onSurfaceCreated() {

progressDialog.dismiss();
launchRouteCalculation();

}

private void launchRouteCalculation() {

SKRouteSettings route = new SKRouteSettings();
route.setStartCoordinate(new SKCoordinate(-122.397674, 37.761278));
route.setDestinationCoordinate(new SKCoordinate(-122.448270, 37.738761));
route.setNoOfRoutes(1);
route.setRouteMode(SKRouteSettings.SKRouteMode.CAR _FASTEST);
route.setRouteExposed(true);

SKRouteManager.getInstance().setRouteListener(this );
SKRouteManager.getInstance().calculateRoute(route) ;

}

}

marbampi
15.04.2015, 13:58
I took a look at the sample project code and I saw that I had to set the advisor settings in the initMapSettings.

This solved my problem.