首页 / 浏览问题 / 移动GIS / 问题详情
java.lang.IllegalArgumentException报错
Ma
3EXP 2021年11月18日

修改了很多错误 最后还是提示我 keep stopping 

报错信息是 at com.example.supermapimobile3d.MainActivity.onCreate(MainActivity.java:23)

1个回答

您好,麻烦提供详细的报错信息
9,232EXP 2021年11月18日

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.supermapimobile3d, PID: 14853
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.supermapimobile3d/com.example.supermapimobile3d.MainActivity}: java.lang.IllegalArgumentException: /storage/emulated/0/SuperMap/license/ is not a correct directory
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3270)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
        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:2016)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7356)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
     Caused by: java.lang.IllegalArgumentException: /storage/emulated/0/SuperMap/license/ is not a correct directory
        at com.supermap.data.Environment.setLicensePath(Environment.java:518)
        at com.example.supermapimobile3d.MainActivity.onCreate(MainActivity.java:23)
        at android.app.Activity.performCreate(Activity.java:7802)
        at android.app.Activity.performCreate(Activity.java:7791)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)

at com.example.supermapimobile3d.MainActivity.onCreate(MainActivity.java:23)别的都是灰色的 只有这一行是蓝色字体了 log里面贴出来的错误

 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        String sdcard= android.os.Environment.getExternalStorageDirectory().getAbsolutePath().toString();
        Environment.setLicensePath(sdcard+"/SuperMap/license/");
        Environment.initialization(this);

        setContentView(R.layout.activity_main);

        Button btnOpen = (Button)findViewById(R.id.btn_open);
        btnOpen.setOnClickListener(new OnClickListener()

您好,您那边设备路径里面有/SuperMap/license路径吗?是否对设备开启了动态权限,设置的targetsdkversion小于或者等于28
您好,我用的Android studio里面的模拟机,需要怎么配置/SuperMap/license路径呢 我看帮助文档里面没有写 我的targetsdkversion是31
模拟器也是需要使用许可的,需要在模拟器对应位置创建文件夹并拷贝许可进去。targetsdkversion建议设置为小于等于28,因为Android10以上使用的是沙盒存储机制,一个app对应一个存储目录
请问模拟机的路径是下载时候的路径吗 然后创建一个SuperMape文件夹 把license拷贝进去吗 targetsdkversion设置为21可以吗
你可以理解为模拟器就是一个手机,你在Android studio里面去设置相关路径,具体可以百度搜索一下。设置为21也是可以的,
好的 十分感谢您!

您好,我按照您说的改完了以后 又出现了新的问题 

现在为Caused by: java.lang.NullPointerException: Attempt to get length of null array
        at com.supermap.data.Environment.checkAndLoadLibrary64(Environment.java:1736)
        at com.supermap.data.Environment.initialization(Environment.java:584)
        at com.example.supermapimobile3d.MainActivity.onCreate(MainActivity.java:24)

  at com.example.supermapimobile3d.MainActivity.onCreate(MainActivity.java:24)这一行报错

Environment.initialization(this);这一行代码的问题
 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        String sdcard= android.os.Environment.getExternalStorageDirectory().getAbsolutePath().toString();
        Environment.setLicensePath(sdcard+"/SuperMap/license/");
        Environment.initialization(this);

        setContentView(R.layout.activity_main);

        Button btnOpen = (Button)findViewById(R.id.btn_open);
        btnOpen.setOnClickListener(new OnClickListener()

这个是因为ndk的原因,需要在build.grandle文件里面设置ndk
好的 我检查一下

我写了

ndk {
    abiFilters 'armeabi-v7a','x86','x86-64'
}以后

又报错了

Installation did not succeed.
The application could not be installed: INSTALL_FAILED_NO_MATCHING_ABIS

List of apks:
[0] 'D:\SuperMapiMobile3D\app\build\outputs\apk\debug\app-debug.apk'
Installation failed due to: 'INSTALL_FAILED_NO_MATCHING_ABIS: Failed to extract native libraries, res=-113'
这是错误原因

android {
    compileSdk 31

    defaultConfig {
        applicationId "com.example.supermapimobile3d"
        minSdk 21
        targetSdk 21
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        ndk {
            abiFilters 'armeabi-v7a','x86'
        }
    splits {
        abi {
            enable true
            reset()
            include 'x86', 'armeabi-v7a', 'x86-64'
            universalApk true
        }
    }
}
    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 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.3.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    implementation files('libs\\com.supermap.data_v1020.jar')
    implementation files('libs\\com.supermap.realspace_v1020.jar')
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}

写了ndk后还是有错误 然后百度写了

splits {
    abi {
        enable true
        reset()
        include 'x86', 'armeabi-v7a', 'x86-64'
        universalApk true
    }

然后又报错

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.supermapimobile3d, PID: 17139
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.supermapimobile3d/com.example.supermapimobile3d.MainActivity}: java.lang.NullPointerException: Attempt to get length of null array
Caused by: java.lang.NullPointerException: Attempt to get length of null array
        at com.supermap.data.Environment.checkAndLoadLibrary64(Environment.java:1736)
        at com.supermap.data.Environment.initialization(Environment.java:584)
        at com.example.supermapimobile3d.MainActivity.onCreate(MainActivity.java:24)

at com.example.supermapimobile3d.MainActivity.onCreate(MainActivity.java:24)还是这行报错

你那边看下libs里面的so文件的文件夹名称是啥?ndk里面就设置这个文件夹名称
是armeabi-v7a  那还需要x86吗
不需要了,只设置armeabi-v7a 就可以
...