Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'com.supermap.mapping.MapControl com.supermap.mapping.MapView.getMapControl()' on a null object reference
行业导航示例时出现调用 getMapControl() 方法时,MapView 对象为 null
private boolean openWorkspace() {
m_Workspace = new Workspace();
WorkspaceConnectionInfo info = new WorkspaceConnectionInfo();
info.setServer(dataPath);
info.setType(WorkspaceType.SMWU);
boolean isOpen = m_Workspace.open(info);
if(!isOpen){
m_MyApp.showInfo("Workspace open failed!");
return false;
}
m_MapView = (MapView) findViewById(R.id.mapview);
m_MapControl = m_MapView.getMapControl();
m_Map = m_MapControl.getMap();
m_Map.setWorkspace(m_Workspace);
//加载高德矢量图 作为地图。0为矢量,1为影像
DatasourceConnectionInfo dsInfo = new DatasourceConnectionInfo();
dsInfo.setEngineType(EngineType.GaoDeMaps);
dsInfo.setDriver("WMTS");
dsInfo.setAlias("gaode");
Datasource ds = m_Workspace.getDatasources().open(dsInfo);
m_Map.getLayers().add(ds.getDatasets().get(0),true);
m_Map.setScale(1/229492.1875);
m_Map.setCenter(new Point2D(12953693.6950684, 4858067.04711915));
m_Map.refresh();
m_MapControl.setGestureDetector(new GestureDetector(longTouchListener));
return true;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//设置一些系统需要用到的路径
requestPermissions() ;
Environment.setLicensePath(MyApplication.SDCARD + "SuperMap/License");
Environment.initialization(this);
m_MyApp = MyApplication.getInstance();
boolean isOpen = openWorkspace();
if(isOpen){
initView();
initNavigation2();
// startDefaultNavi();
}
}