java.lang.NoClassDefFoundError: java.util.Objects
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
}
In my case this exception happened on Android 4 after upgrade to Retrofit
2.7.1.
See https://github.com/square/retrofit/blob/master/CHANGELOG.md:
Version 2.7.0 (2019-12-09)
This release changes the minimum requirements to Java 8+ or Android 5+. See this blog post for more information on the change.
New: Upgrade to OkHttp 3.14.4. Please see its changelog for 3.x.
See also https://github.com/square/retrofit/issues/3201 and https://github.com/square/retrofit/issues/3042.
Retrofit
depends on OkHttp
that refused pre API 21 support in version 3.13.
So, downgrade Retrofit
to 2.6.4 or even before 2.6.0. I checked, it solved the problem. Also downgrade Retrofit Gson converter (com.squareup.retrofit2:converter-gson) to 2.6.4.