【问题标题】:Ljava/time/ZoneId Crash for AndroidAndroid 的 Ljava/time/ZoneId 崩溃
【发布时间】:2021-05-31 07:39:23
【问题描述】:

我在我的应用程序中运行了以下日期代码,但在 android 6.0 LGE 设备上出现了崩溃。我该如何解决这个问题?为什么会出现问题?

问候

Fatal Exception: java.lang.NoClassDefFoundError
Failed resolution of: Ljava/time/ZoneId;

Caused by java.lang.ClassNotFoundException: Didn't find class "java.time.ZoneId" on path: DexPathList[[zip file "/data/app/com.myapp.test.trast.oppolar-1/base.apk", zip file "/data/app/com.myapp.test.trast.oppolar-1/split_config.ar.apk", zip file "/data/app/com.myapp.test.trast.oppolar-1/split_config.tr.apk", zip file "/data/app/com.myapp.test.trast.oppolar-1/split_config.xxxhdpi.apk"],nativeLibraryDirectories=[/data/app/com.myapp.test.trast.oppolar-1/lib/arm64, /vendor/lib64, /system/lib64]]

我的代码:

ZoneId z = ZoneId.of(String.valueOf(ZoneId.systemDefault()));
LocalDate ld = LocalDate.parse(currentDateandTime);
ZonedDateTime zdtStart = ld.atStartOfDay(z);
Instant instantStart = zdtStart.toInstant();
long start = instantStart.getEpochSecond() * 1000;

LocalDate nextDay = ld.plusDays(1);
ZonedDateTime zdtEnd = nextDay.atStartOfDay(z);
Instant instantEnd = zdtEnd.toInstant();
long end = instantEnd.getEpochSecond() * 1000;

【问题讨论】:

    标签: java android time


    【解决方案1】:

    因为您使用的是“java.time”包,而这个包是在 api 26 中添加的。 https://developer.android.com/reference/java/time/package-summary

    【讨论】:

    • 如何在低于 sdk 26 的用户上运行它?
    • 通过快速研究,我发现这个库用于将“java.time”与较旧的 api 一起使用。您可以查看:github.com/JakeWharton/ThreeTenABP
    • 我想我用代码 coreLibraryDesugaringEnabled true 解决了我的问题。谢谢
    猜你喜欢
    • 1970-01-01
    • 2020-10-31
    • 2020-07-05
    • 1970-01-01
    • 2018-02-23
    • 1970-01-01
    • 2018-02-07
    • 2012-07-07
    • 2012-12-27
    相关资源
    最近更新 更多