java.lang.NoClassDefFoundError:无法解决以下问题:Ljava/time/LocalDate;错误 [英] java.lang.NoClassDefFoundError: Failed resolution of: Ljava/time/LocalDate; error

查看:1236
本文介绍了java.lang.NoClassDefFoundError:无法解决以下问题:Ljava/time/LocalDate;错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了一切,但错误没有得到解决

I tried everything, but the error not getting solved

这是我的代码:

public String[] getWeekDays() {

    LocalDate today = LocalDate.now();
    LocalDate monday = today;
    LocalDate tue = today;
    LocalDate wed = today;
    LocalDate thur = today;
    LocalDate fri = today;
    LocalDate sat = today;
    LocalDate sunday = today;
    while (sunday.getDayOfWeek() != DayOfWeek.SUNDAY){
        sunday = sunday.minusDays(1);
     }
     while (monday.getDayOfWeek() != DayOfWeek.MONDAY){
        monday = monday.minusDays(1);
     }
     while (tue.getDayOfWeek() != DayOfWeek.TUESDAY){
        tue = tue.plusDays(1);
     }
     while (wed.getDayOfWeek() != DayOfWeek.WEDNESDAY){
        wed = wed.plusDays(1);
     }
     while (thur.getDayOfWeek() != DayOfWeek.THURSDAY){
        thur = thur.plusDays(1);
     }
     while (fri.getDayOfWeek() != DayOfWeek.FRIDAY){
        fri = fri.plusDays(1);
     }
     while (sat.getDayOfWeek() != DayOfWeek.SATURDAY){
        sat = sat.plusDays(1);
     }

     String[] days = {String.valueOf(sunday),String.valueOf(monday), String.valueOf(tue), String.valueOf(wed),
                String.valueOf(thur), String.valueOf(fri), String.valueOf(sat)};
    return days;
}

我已编写代码以获取一个星期的日期.当我运行此代码时,LocalDate.now();出现错误.该错误是"java.lang.NoClassDefFoundError:无法解决以下问题:Ljava/time/LocalDate;". 我已经在网上搜索了.有人说它要求API级别至少为27.我对API 27级别感到厌倦,但该错误未得到解决.我的目标设备更多地是我需要在此API级别上运行的API 26.并且还尝试添加编译" java.time:LocalTime:1.8".这也是行不通的. 请帮助我...

I have written the code to get dates of one week. When I running this code, i am getting an error at LocalDate.now();. The error is "java.lang.NoClassDefFoundError: Failed resolution of: Ljava/time/LocalDate;". I have searched on the net. Some are saying it requires API level min 27. I have tired on API 27 level but the error didn't get resolved. More ever my target device is API 26 I needed to run on this API level. And also tried adding "compile "java.time:LocalTime:1.8" ". This one also doesn't work. Please help me...

推荐答案

NoClassDefFoundError -如果Java虚拟机或 ClassLoader实例尝试加载类的定义(如 普通方法调用的一部分或创建新实例的一部分 使用新的表达式),则无法定义该类 找到了.

NoClassDefFoundError-Thrown if the Java Virtual Machine or a ClassLoader instance tries to load in the definition of a class (as part of a normal method call or as part of creating a new instance using the new expression) and no definition of the class could be found.

LocalDate today = LocalDate.now(); // Added 1.8

阅读 LocalDate >

请确保您已在build.gradle部分中添加了此内容.

Make sure, You added this in your build.gradle section.

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
    }

仅供参考

java.time 程序包仅在API 26中添加.

java.time package was added only in API 26.

所以,您应该设置

 minSdkVersion 26

此后, Clean-Rebuild-Gradle .

After that, Clean-Rebuild-Gradle.

这篇关于java.lang.NoClassDefFoundError:无法解决以下问题:Ljava/time/LocalDate;错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆