首页 / 浏览问题 / 移动GIS / 问题详情
入门示例 安卓APP闪退
1EXP 2022年09月06日

使用产品:supermap imobile 10i(2021) for android

操作系统:win10 x64;手机操作系统:华为p40

问题详细描述:

按照示例写完代码后,显示数组下标越

 Process: com.example.supermap, PID: 19273
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.supermap/com.example.supermap.MainActivity}: java.lang.IndexOutOfBoundsException: index
    索引越界
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3554)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3738)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:86)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2226)
        at android.os.Handler.dispatchMessage(Handler.java:112)
        at android.os.Looper.loop(Looper.java:216)
        at android.app.ActivityThread.main(ActivityThread.java:7779)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:990)
     Caused by: java.lang.IndexOutOfBoundsException: index
    索引越界
        at com.supermap.data.Maps.get(Maps.java:81)
        at com.example.supermap.MainActivity.onCreate(MainActivity.java:50)
        at android.app.Activity.performCreate(Activity.java:7458)
        at android.app.Activity.performCreate(Activity.java:7448)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1286)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3533)
            ... 11 more

具体代码如下

public class MainActivity extends AppCompatActivity {
    private static final String TAG = "MainActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestPermissions();
        MapControl mapControl = null;
        String rootPath = android.os.Environment.getExternalStorageDirectory().getAbsolutePath();
        //设置许可文件路径(默认路径“/SuperMap/license/”)
        Environment.setLicensePath(rootPath + "/SuperMap/license/");

        //组件功能必须在Environment初始化之后才能调用
        Environment.initialization(getApplicationContext());
        setContentView(R.layout.activity_main);
        //打开工作空间
        Workspace m_workspace = new Workspace();
        WorkspaceConnectionInfo info = new WorkspaceConnectionInfo();
        info.setServer(rootPath + "/SampleData/GeometryInfo/World.smwu");
        info.setType(WorkspaceType.SMWU);
        m_workspace.open(info);

        //将地图显示控件和工作空间关联
        MapView m_mapView = findViewById(R.id.Map_view);
        mapControl = m_mapView.getMapControl();
        mapControl.getMap().setWorkspace(m_workspace);
//        打开工作空间中的第二幅地图
        String mapName = m_workspace.getMaps().get(1);
        mapControl.getMap().open(mapName);
        mapControl.getMap().refresh();
    }

    private void requestPermissions() { //Android6.0以上设备设置动态权限
        if (Build.VERSION.SDK_INT >= 23) {
            // 检查是否拥有权限
            String[] permissions = {
                    Manifest.permission.WRITE_EXTERNAL_STORAGE,
                    Manifest.permission.ACCESS_FINE_LOCATION,
                    Manifest.permission.READ_PHONE_STATE,
                    Manifest.permission.ACCESS_WIFI_STATE,
                    Manifest.permission.ACCESS_NETWORK_STATE,
                    Manifest.permission.CHANGE_WIFI_STATE,
            };
            String permission = null;
            int id = 0;
            boolean isBreak = false;
            int checkCallPhonePermission = 0;
            for (int i = 0; i < permissions.length; i++) {
                permission = permissions[i];
                checkCallPhonePermission = checkSelfPermission(permission);
                if (checkCallPhonePermission != PackageManager.PERMISSION_GRANTED) {
                    requestPermissions(permissions, id);
                    isBreak = true;
                    break;
                }
            }
        }

    }

}

1个回答

您好,提示索引是因为工作空间中没有两张地图,您那边检查一下呢
3,685EXP 2022年09月06日
...