Java.lang.NoClassDefFoundError : Failed resolution of: Ljava/time/LocalDate; error error
Tried everything, still didn’t solve it
Here is my code :
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;
}
I’ve written code to get the day of the week. When I run this code, I run this code in LocalDate.now(); An error was received at . The error is “java.lang.NoClassDefFoundError: parsing failed: Ljava/time/localDate; ”。
I searched online. Some say it requires an API level of a minimum of 27. I’m tired of API 27 levels, but the error is not resolved. I have more and more target devices and I need to run API 26 at this API level. And try adding “compile” java.time:LocalTime:1.8″. This one won’t work either.
Please help me….
Solution
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
Read LocalDate
Make sure you added it in the build.gradle section.
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
For reference only
The java.time
package was only added in API 26.
So, you should set it
up
minSdkVersion 26
After that, Clean-Rebuild-Gradle
.