首页 / 浏览问题 / 移动GIS / 问题详情
为什么安装的app打不开
30EXP 2022年10月14日

使用产品:iMobile 11i 操作系统:win11 x64

问题详细描述:app出现闪退,一下为错误代码:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.supermapimobile2d, PID: 26511
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.supermapimobile2d/com.example.supermapimobile2d.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.File android.content.Context.getFilesDir()' on a null object reference
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3754)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3912)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2319)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:257)
        at android.app.ActivityThread.main(ActivityThread.java:8228)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:626)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1032)
     Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.File android.content.Context.getFilesDir()' on a null object reference
        at com.supermap.data.Environment.checkAndLoadLibrary(Environment.java:1612)
        at com.supermap.data.Environment.initialization(Environment.java:585)
        at com.example.supermapimobile2d.MainActivity.onCreate(MainActivity.java:25)
        at android.app.Activity.performCreate(Activity.java:8129)
        at android.app.Activity.performCreate(Activity.java:8113)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1359)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3727)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3912) 
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2319) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:257) 
        at android.app.ActivityThread.main(ActivityThread.java:8228) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:626) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1032) 

下为代码:

package com.example.supermapimobile2d;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.os.Bundle;
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 Context context;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        MapControl mapControl = null;
        String rootPath = android.os.Environment.getExternalStorageDirectory().getAbsolutePath();

        //设置许可文件路径(默认路径“/SuperMap/license/”)
        Environment.setLicensePath(rootPath + "/supermap1/license/");

        //组件功能必须在Environment初始化之后才能调用
        Environment.initialization(context);

        setContentView(R.layout.activity_main);

        //打开工作空间
        Workspace m_workspace = new Workspace();
        WorkspaceConnectionInfo info = new WorkspaceConnectionInfo();
        info.setServer(rootPath + "/supermap1/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();
    }
}

1个回答

您好,看您的报错信息是“Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.File android.content.Context.getFilesDir()' on a null object reference”错误位置在“Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.File android.content.Context.getFilesDir()' on a null object reference”初始化环境时错误,建议您检查一下build.gradle里面是否有添加ndk,还有是否有targetSdkVersion和compileSdkVersion是否为28
3,735EXP 2022年10月14日

您好,这个我一开始就添加了了ndk,还是不行。

下面是build.gradle里的代码

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    buildToolsVersion "29.0.3"

    defaultConfig {
        applicationId "com.example.supermapimobile2d"
        minSdkVersion 23
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        ndk {
            abiFilters 'armeabi-v7a'
        }

    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    sourceSets {
        main {
            jniLibs.srcDirs = ['libs']
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

}

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation files('libs\\com.supermap.data_v1100.jar')
    implementation files('libs\\com.supermap.mapping_v1100.jar')
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

}

那个,我刚才试了一下,把build.gradle里的ndk去掉跑了一下,跟添加ndk一个错误。sad

您好,您可以看下这份工程,这边运行没问题的

链接:https://pan.baidu.com/s/1okyNH0YlnHpKn6xEQAXjRA?pwd=8754
提取码:8754
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.bestyou.myapplication, PID: 10416
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.bestyou.myapplication/com.bestyou.myapplication.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'char[] java.lang.String.toCharArray()' on a null object reference
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3754)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3912)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2319)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:257)
        at android.app.ActivityThread.main(ActivityThread.java:8228)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:626)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1032)
     Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'char[] java.lang.String.toCharArray()' on a null object reference
        at com.supermap.data.Environment.encryptionMac(Environment.java:2283)
        at com.supermap.data.Environment.writeFile(Environment.java:2312)
        at com.supermap.data.Environment.checkDevice_New(Environment.java:836)
        at com.supermap.data.Environment.initialization(Environment.java:626)
        at com.bestyou.myapplication.MainActivity.onCreate(MainActivity.java:75)
        at android.app.Activity.performCreate(Activity.java:8129)
        at android.app.Activity.performCreate(Activity.java:8113)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1359)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3727)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3912)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2319)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:257)
        at android.app.ActivityThread.main(ActivityThread.java:8228)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:626)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1032)、

您好,你发的项目 我们运行发现 报这个错 请问怎么解决呀
您好,私信您了,麻烦给下联系方式呢
那个私信好像打不开,我在这说了qq:2582055425
更换有效许可后正常
...