我想请问一下,我想使用Android studio做一个三维导航,但是现在把指导书里的代码放进去过后,运行app到模拟器上之后,就会闪退。我已经把配置许可放到指定路径下面了,但是还是会闪退,想问一下这是为什么呢,现在把报错日志粘贴上来
03-24 01:34:34.793 15899-15899/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.loadscence, PID: 15899
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.loadscence/com.example.loadscence.MainActivity}: java.lang.NullPointerException: Attempt to get length of null array
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.NullPointerException: Attempt to get length of null array
at com.supermap.data.Environment.checkAndLoadLibrary64(Environment.java:1632)
at com.supermap.data.Environment.initialization(Environment.java:576)
at com.example.loadscence.MainActivity.onCreate(MainActivity.java:34)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
以下是mainactivity代码
package com.example.loadscence;
import androidx.appcompat.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ZoomControls;
import com.supermap.data.Environment;
import com.supermap.data.Workspace;
import com.supermap.data.WorkspaceConnectionInfo;
import com.supermap.data.WorkspaceType;
import com.supermap.mapping.MapControl;
import com.supermap.mapping.MapView;
public class MainActivity extends AppCompatActivity {
private MapControl m_mapcontrol = null;
private Workspace m_workspace;
private MapView m_mapView;
private ZoomControls m_zoom;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//设置一些系统需要用到的路径
String rootPath =
android.os.Environment.getExternalStorageDirectory().getAbsolutePath();
Environment. setLicensePath (rootPath + "/SuperMap/license/");
Environment. setTemporaryPath (rootPath + "/SuperMap/temp/");
Environment. setWebCacheDirectory (rootPath + "/SuperMap/WebCatch");
//组件功能必须在 Environment 初始化之后才能调用
Environment. initialization (this);
//如果机器中默认不包括需要显示的字体,可以把相关字体文件放在参数所代表的路径中。
//例如,如果需要显示阿拉伯文字(若机器中原先不包括相关字体文件),可以把需要的字体文件放在参数所代表的路径中。
Environment. setFontsPath (rootPath + "/SuperMap/fonts/");
setContentView(R.layout. activity_main );
//打开工作空间
m_workspace = new Workspace();
WorkspaceConnectionInfo info = new WorkspaceConnectionInfo();
info.setServer(rootPath + "/SampleData/GeometryInfo/World.smwu");
info.setType(WorkspaceType. SMWU );
m_workspace.open(info);
//将地图显示控件和工作空间关联
m_mapView = (MapView)findViewById(R.id. Map_view );
m_mapcontrol = m_mapView.getMapControl();
m_mapcontrol.getMap().setWorkspace(m_workspace);
//打开工作空间中的第二幅地图
String mapName = m_workspace.getMaps().get(1);
m_mapcontrol.getMap().open(mapName);
m_zoom = (ZoomControls)findViewById(R.id. zoomControls1 );
m_mapView = (MapView)findViewById(R.id. Map_view );
m_zoom.setIsZoomInEnabled(true);
m_zoom.setIsZoomOutEnabled(true);
//放大按钮
m_zoom.setOnZoomInClickListener(new OnClickListener() {
public void onClick(View v) {
m_mapcontrol.getMap().zoom(2);
m_mapcontrol.getMap().refresh();
}
});
//缩小按钮
m_zoom.setOnZoomOutClickListener(new OnClickListener(){
public void onClick(View v) {
m_mapcontrol.getMap().zoom(0.5);
m_mapcontrol.getMap().refresh();
}
});
m_mapcontrol.getMap().refresh();
}
}