java.lang.NoClassDefFoundError: java.util.Objects

前端 未结 2 1974
囚心锁ツ
囚心锁ツ 2020-12-06 11:06

I\'m getting the following crash report in Android development Console. My app runs fine on the simulator or devices that I tried the app on, but for some reason on a Galaxy

2条回答
  •  悲哀的现实
    2020-12-06 11:57

    The exception is thrown because all static methods of java.util.Objects are available above API 19 (Android 4.4.+).

    As you said in comments, your device has API 10 (Android 2.3.+) so that method doesn't exist in that Android version and NoClassDefFoundError is thrown.

    If you want to check api level programmatically you can do:

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        // your code available only above api 19
    } else {
        // compatibility code
    }
    

提交回复
热议问题