我想在我的Android应用程序中集成一个地图。但我刚从基础开始,我已经遇到了崩溃/错误。
我刚刚从演示项目中复制了一些代码,但仍然没有运气。
Logcat:
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);
}
答案 0 :(得分:1)
我遇到了同样的问题,我在他们的支持论坛上发了一个答案:
您好,
在我的Android应用程序中实现Skobbler,我陷入了半小时的崩溃我无法理解。 在初始化部分的DemoApp之后,我在地图显示错误之前一直崩溃:
java.lang.NullPointerException
at com.skobbler.ngx.map.MapRenderer.onSurfaceCreated( SourceFile:487)
at android.opengl.GLSurfaceView$GLThread.guardedRun(G LSurfaceView.java:1509)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfac eView.java:1248)
由于错误根本不是自我解释,我从包com.skobbler.ngx.map调查了文件MapRenderer,并找到了 我崩溃了,因为我没有实现一个地图监听器(this.s,在下面一行),哪个类名试图在日志中显示。
public final void onSurfaceCreated(GL10 arg1, EGLConfig paramEGLConfig)
{
SKLogging.writeLog("MapRenderer", "onSurfaceCreated before LOCK ", 2);
synchronized (V) {
SKLogging.writeLog("MapRenderer", "onSurfaceCreated" + this.s.getClass().getName(), 2); // <== Line 487
您可能忘记在记录之前检查this.s的非nullity,并且因为在您的doc中没有将其描述为强制性的 实现这个监听器,我认为你应该纠正这个问题,或者在文档中对其进行精确处理。
希望有所帮助!
tl:dr:
SKMapSurfaceView mapView = mapViewContainer.getMapSurfaceView();
mapView.setMapSurfaceListener(new SKMapSurfaceListener() {...});