-1

我想在我的 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);
}
4

1 回答 1

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 之前检查它的非空性,并且由于在您的文档中没有将其描述为强制实现此侦听器,我认为您应该更正它,或者在文档中精确它。

http://forum.skobbler.com/showthread.php/6554-Android-Resolution-for-NullPointerException-onSurfaceCreated(SourceFile-487)?p=17601#post17601

希望有帮助!

tl:博士:

SKMapSurfaceView mapView = mapViewContainer.getMapSurfaceView();
mapView.setMapSurfaceListener(new SKMapSurfaceListener() {...});
于 2014-09-15T11:34:18.860 回答