工作空间内的road读取失败,
Process: com.example.navi, PID: 23493
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.navi/com.example.navi.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'com.supermap.data.Datasets com.supermap.data.Datasource.getDatasets()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2946)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3081)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
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:1831)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:201)
at android.app.ActivityThread.main(ActivityThread.java:6810)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'com.supermap.data.Datasets com.supermap.data.Datasource.getDatasets()' on a null object reference
at com.example.navi.MainActivity.initNavigation2(MainActivity.java:239)
at com.example.navi.MainActivity.onCreate(MainActivity.java:111)
at android.app.Activity.performCreate(Activity.java:7224)
at android.app.Activity.performCreate(Activity.java:7213)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1272)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2926)
问题代码行
private void initNavigation2() {
String networkDatasetName = "road_Network"; // 已有的网络数据集的名称
// 初始化行业导航对象
DatasetVector networkDataset = (DatasetVector) m_Workspace.getDatasources().get("road").getDatasets().get(networkDatasetName);
m_Navigation2 = m_MapControl.getNavigation2(); // 获取行业导航控件,只能通过此方法初始化m_Navigation2
m_Navigation2.setPathVisible(true); // 设置分析所得路径可见
m_Navigation2.setNetworkDataset(networkDataset); // 设置网络数据集
m_Navigation2.loadModel( rootPath + "/SuperMap/cug_data/NetworkModel.snm"); // 加载网络模型
m_Navigation2.addNaviInfoListener(new NaviListener() {