I'm using ThreeTen-Backport library for my Android project (because java.time is not yet implemented in android development).
When I write LocalDate today=LocalDate.now();
or LocalTime time=LocalTime.now();
I get the following exception:
Caused by: org.threeten.bp.zone.ZoneRulesException:
No time-zone data files registered
at org.threeten.bp.zone.ZoneRulesProvider.getProvider(ZoneRulesProvider.java:176)
at org.threeten.bp.zone.ZoneRulesProvider.getRules(ZoneRulesProvider.java:133)
at org.threeten.bp.ZoneRegion.ofId(ZoneRegion.java:143)
at org.threeten.bp.ZoneId.of(ZoneId.java:357)
at org.threeten.bp.ZoneId.of(ZoneId.java:285)
at org.threeten.bp.ZoneId.systemDefault(ZoneId.java:244)
at org.threeten.bp.Clock.systemDefaultZone(Clock.java:137)
at org.threeten.bp.LocalDate.now(LocalDate.java:165)
The same line of code works well in another java project I have, which uses the native java.time library.
I searched for a possible solution but couldn't find anything useful: one solution suggested I need to use another jar that includes the time-zone rules and other suggested that there might be two or more ThreeTenBP-libraries inside the classpath.
Those cases don't match my case.
Inside the build.gradle
file, at the dependencies section, I've tried few configurations:
- At first, I used -
compile 'com.jakewharton.threetenabp:threetenabp:1.0.3'
- Then, I tried -
compile 'org.threeten:threetenbp:1.0.3'
- After that, I tried -
compile 'org.threeten:threetenbp:1.3.1'
- Currently, I use
compile 'org.threeten:threetenbp:1.3.2'
I don't know what is wrong with that line of code and how to fix it.
The LocalDate.now()
and LocalTime.now()
methods should work without specifying a time zone.
AndroidThreeTen.init(this);
code. I thought to add this in the activity'sonCreate
method but I saw it wasn't right. Now I've created a new class which extends the application class and put that line in theonCreate
method. Now everything works just great! – Disclose