首页 / 浏览问题 / 移动GIS / 问题详情
NullPointerException导致无法初始化
1EXP 2022年07月14日

使用产品:imobile 10.2 操作系统:win10 x64 华为OS(相当于安卓10)
数据类型: 文件型
问题详细描述:跟着3、SuperMap iMobile for Android快速入门-Android教程-腾讯课堂 (qq.com)网页的教程做,遇到java.lang.NullPointerException错误。

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

        //指定路径,新建文件夹
        Environment.setLicensePath("/sdcard/SuperMap/License/");
        Environment.setWebCacheDirectory("/sdcard/SuperMap/WebCache/");
        Environment.setTemporaryPath("/sdcard/SuperMap/temp/");
//        Environment.getLicenseStatus();
        //初始化
        Environment.initialization(this);
        setContentView(R.layout.activity_main);

        //打开工作空间
        Workspace world = new Workspace();
        WorkspaceConnectionInfo info = new WorkspaceConnectionInfo();
        info.setServer("/sdcard/SuperMap/GeometryInfo/World.smwu");
        info.setType(WorkspaceType.SMWU);
        world.open(info);

        //关联地图显示控件和工作空间
        MapControl mapControl = findViewById(R.id.mapControl);
        mapControl.getMap().setWorkspace(world);

        //打开第一幅地图
        String mapName = world.getMaps().get(0);
        mapControl.getMap().open(mapName);
        mapControl.getMap().refresh();

    }


问题重现步骤: 1.在onCreate函数里打断点,然后调试

2.Environment.initialization(this) 初始化报错

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.supermaptest, PID: 18099
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.supermaptest/com.example.supermaptest.MainActivity}: java.lang.NullPointerException
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4060)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4247)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:91)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2613)
        at android.os.Handler.dispatchMessage(Handler.java:110)
        at android.os.Looper.loop(Looper.java:219)
        at android.app.ActivityThread.main(ActivityThread.java:8668)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1109)
     Caused by: java.lang.NullPointerException
        at java.util.Objects.requireNonNull(Objects.java:203)
        at java.util.Arrays$ArrayList.<init>(Arrays.java:3738)
        at java.util.Arrays.asList(Arrays.java:3725)
        at com.supermap.data.Environment.checkAndLoadLibrary64(Environment.java:1760)
        at com.supermap.data.Environment.initialization(Environment.java:587)
        at com.example.supermaptest.MainActivity.onCreate(MainActivity.java:30)
        at android.app.Activity.performCreate(Activity.java:8214)
        at android.app.Activity.performCreate(Activity.java:8202)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1320)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4033)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4247) 
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:91) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2613) 
        at android.os.Handler.dispatchMessage(Handler.java:110) 
        at android.os.Looper.loop(Looper.java:219) 
        at android.app.ActivityThread.main(ActivityThread.java:8668) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1109) 

2 个回答

您好,请问您是否有做以下操作

1.app申请读取等相关,

2.测试机上是否权限打开,

3.如果上述两步还是不行,在debug模式下查看是否读取到许可路径

4.更换许可,重新申请试用许可

5.如果都不行,请下载Supermap Itablet查看是否可用
3,745EXP 2022年07月14日
你好,我在debug模式下如何查看是否读取到许可路径?用什么函数,添加到哪里?

如果是以下代码,调试的时候会出现Source code does not match the bytecode这一句,初始化失败,不会运行get函数。

        Environment.initialization(this);
        Environment.getLicenseStatus();

如果调换这两句代码,那么会报错

Caused by: java.lang.IllegalStateException: Please call com.supermap.data.Environment.initialization() firstly

也就是需要先初始化。

可能是库没有导入,需要在app的build.gradle文件下加上

sourceSets {
    main{
        jniLibs.srcDirs=['libs']
    }
}
14EXP 2022年07月17日
已经添加了,谢谢你
...