我想在我的 android 应用程序中集成地图。但我只是从基础开始,我已经遇到了崩溃/错误。
我刚刚从演示项目中复制了一些代码,但仍然没有运气。
日志猫:
08-14 16:19:55.703: E/AndroidRuntime(30065): FATAL EXCEPTION: GLThread 787
08-14 16:19:55.703: E/AndroidRuntime(30065): java.lang.NullPointerException
08-14 16:19:55.703: E/AndroidRuntime(30065): at com.skobbler.ngx.map.MapRenderer.onSurfaceCreated(SourceFile:487)
08-14 16:19:55.703: E/AndroidRuntime(30065): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1509)
08-14 16:19:55.703: E/AndroidRuntime(30065): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1248)
我已经研究过,但我还没有找到任何解决方案。请帮忙。
这是我的代码:MainActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SKLogging.enableLogs(true);
File externalDir = getExternalFilesDir(null);
if (externalDir != null) {`enter code here`
mapresDirPath = externalDir + "/SKMaps/";
} else {
mapresDirPath = getFilesDir() + "/SKMaps/";
}
if (!new File(mapresDirPath).exists()) {
new SKPrepareMapTextureThread(this, mapresDirPath, "SKMaps.zip", this).start();
copyOtherResources();
prepareMapCreatorFile();
} else {
Toast.makeText(MainActivity.this, "Map resources copied in a previous run", Toast.LENGTH_SHORT).show();
prepareMapCreatorFile();
initializeLibrary();
finish();
startActivity(new Intent(MainActivity.this, MapActivity.class));
}
}
private void initializeLibrary() {
SKMapsInitSettings initSettings = new SKMapsInitSettings();
initSettings.setMapResourcesPaths(mapresDirPath, new SKMapViewStyle(mapresDirPath + "daystyle/", "daystyle.json"));
final SKAdvisorSettings advisorSettings = initSettings.getAdvisorSettings();
advisorSettings.setLanguage("en");
advisorSettings.setAdvisorVoice("en");
advisorSettings.setPlayInitialAdvice(true);
advisorSettings.setPlayAfterTurnInformalAdvice(true);
advisorSettings.setPlayInitialVoiceNoRouteAdvice(true);
initSettings.setAdvisorSettings(advisorSettings);
SKVersioningManager.getInstance().setMapUpdateListener(this);
SKMaps.getInstance().initializeSKMaps(this, initSettings, API_KEY);
}
@Override
public void onMapTexturesPrepared(boolean prepared) {
initializeLibrary();
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(MainActivity.this, "Map resources were copied", Toast.LENGTH_SHORT).show();
finish();
startActivity(new Intent(MainActivity.this, MapActivity.class));
}
});
}
MapActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
SKMapViewHolder mapViewHolder = (SKMapViewHolder) findViewById(R.id.map_surface_holder);
mapView = mapViewHolder.getMapSurfaceView();
mapView.getMapSettings().setMapPanningEnabled(true);
mapView.getMapSettings().setMapZoomingEnabled(true);
mapView.getMapSettings().setInertiaPanningEnabled(true);
SKVersioningManager.getInstance().setMapUpdateListener(this);
}