This question already has answers here:
Only some users reporting "Resource Not Found" error. Does this make sense?
(4 answers)
Closed 7 years ago.
I'm trying to take a String and convert it to another String in a more readable format:
String startTime = invite.get_start_time();
Log.d(LOG_TAG, "String to be converted is " + startTime);
DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
DateTime dt = fmt.parseDateTime(startTime);
invite.set_start_time(dt.toString("MM dd yyyy hh:mmaa"));
08-02 14:33:19.011: D/InvitesObjectListAdapter(856): String to be
converted is 2015-08-03 10:30:00 08-02 14:33:19.041:
W/System.err(856): java.io.IOException: Resource not found:
"org/joda/time/tz/data/ZoneInfoMap" ClassLoader:
dalvik.system.PathClassLoader[DexPathList[[zip file
"/data/app/me.lunchbunch.core-1/base.apk"],nativeLibraryDirectories=[/vendor/lib64,
/system/lib64]]]
Anyone know where this error comes from?
Sorry for wasting peoples' times, #adelphus is correct - I did not initialize with:
JodaTimeAndroid.init(this);
It was in my code, but I need to refactor to ensure this is hit.
Related
This question already has an answer here:
Spring SpEL expression evaluation for an application yml property
(1 answer)
Closed 1 year ago.
I'm using SpringBoot.
In previous projects I was using application.property file, and content looks look this:
seconds.timeOut=10
interval.milliseconds.cleaner=#{${seconds.timeOut}*2*1000}
interval.seconds.cleanerOffset=#{${seconds.timeOut}*3}
result was correct cleaner=20000 and cleanerOffset=30
In new project I switch to application.yml file. Have same configuration:
seconds:
timeOut: 10
interval:
milliseconds:
cleaner: ${seconds.timeOut}*2*1000
interval:
seconds:
cleanerOffset: ${seconds.timeOut}*3
but result is string cleaner = "10*2*1000"
Of course I have exception:
Caused by: java.lang.IllegalStateException: Encountered invalid #Scheduled method 'cleaningWorker': Invalid fixedDelayString value "10*2*1000" - cannot parse into long
I can't found any workaround could you help me?
Thanks for all.
this solution for me:
seconds:
timeOut: 10
interval:
milliseconds:
cleaner: '#{${seconds.timeOut}*2*1000}'
interval:
seconds:
cleanerOffset: '#{${seconds.timeOut}*3}'
Try:
$(( ${seconds.timeOut} * 2000seconds ))
If this didn't work please refer to this, this will help.
jdk used : 1.8
Not sure what is the issue, configuredFormat is valid one, inputTime is also valid one, really confused what is the issue.
public class Test {
public static void main(String[] args) {
String configuredFormat = "yyyyMMddHHmmssSSS";
String inputTime = "20200203164553123";
DateTimeFormatter dt = DateTimeFormatter.ofPattern(configuredFormat);
DateTimeFormatter strictTimeFormatter = dt.withResolverStyle(ResolverStyle.STRICT);
try {
LocalTime.parse(inputTime, strictTimeFormatter);
System.out.println("success");
} catch (DateTimeParseException | NullPointerException e) {
e.printStackTrace();
}
}
}
Exception I am Getting :
java.time.format.DateTimeParseException: Text '20200203164553123' could not be parsed at index 0
at java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1949)
at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1851)
at java.time.LocalTime.parse(LocalTime.java:441)
at com.Test.main(Test.java:20)
Lucky for you, there is an exact bug report which uses the exact same pattern that you're trying. Who better to explain than the JDK maintainers?
JDK-8031085
Workaround
DateTimeFormatter dtf = new
DateTimeFormatterBuilder()
.appendPattern("yyyyMMddHHmmss")
.appendValue(ChronoField.MILLI_OF_SECOND,3)
.toFormatter()
Adjacent value parsing is generally a hard problem. It is intended to
handle the case where the first element is variable width (the year)
and all other elements are fixed width (month, day etc). However, the
"S" pattern letter is a fraction, not a value. Specifically, the
fraction can be variable width - more or less than three digits are
possible options. Given the general case of a variable width year and
a variable width millisecond, it is not possible to determine which of
the two fields was intended to be variable.
Having said that, the implementation (and javadoc) have not ended up
as I intended. The description of "fraction" in DateTimeFormatter
describes actions in strict and lenient mode, but there is no way to
access strict or lenient mode when using
DateTimeFormatter.ofPattern(). This is a documentation bug that should
be fixed by removing the discussion of strict vs lenient.
Worse however is that the SSS pattern has therefore ended up using
strict mode when lenient mode would be appropriate. As it currently
stands, DateTimeFormatter.ofPattern("hhmmss.SSS") requires three
digits for milliseconds, when it was originally intended to require 0
to 9 (the lenient behaviour).
I tried changing the whole of the DateTimeFormatter.ofPattern() method
to use lenient parsing, and it broke no tests (which is bad in its own
way). This might be a valid fix, but only if included in JDK 8, as
once people adapt to the strict parsing it will be hard to make it
lenient.
Given that the current implementation requires three digits for SSS,
it is thus very surprising that adjacent value parsing does not apply.
Actually I agree format should be valid... this seems to be confirmed as I tried with both oracle java 8 and 9 runtime, and with java 9 it does not happen. (I tried IBM jre 8 too and it works as well)
System.out.println( System.getProperty( "java.vendor" )+" - "+System.getProperty( "java.version" ) );
String configuredFormat = "yyyyMMddHHmmssSSS";
String inputTime = "20200203164553123";
DateTimeFormatter dt = DateTimeFormatter.ofPattern(configuredFormat);
DateTimeFormatter strictTimeFormatter = dt.withResolverStyle(ResolverStyle.STRICT);
try {
//System.out.println( dt.parse( inputTime ) );
LocalTime.parse(inputTime, strictTimeFormatter);
System.out.println("success");
} catch (DateTimeParseException | NullPointerException e) {
e.printStackTrace();
}
Output
Oracle Corporation - 9.0.4
success
IBM Corporation - 1.8.0_211
success
Oracle Corporation - 1.8.0_172
java.time.format.DateTimeParseException: Text '20200203164553123' could not be parsed at index 0
at java.time.format.DateTimeFormatter.parseResolved0(Unknown Source)
at java.time.format.DateTimeFormatter.parse(Unknown Source)
at java.time.LocalTime.parse(Unknown Source)
at test.Test2.main(Test2.java:19)
I'm trying to localize for Finland using this code:
Locale finLocale = new Locale("fi", "FI");
Date today = new Date(2017, 1, 1);
DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.LONG, finLocale);
String formattedDate = dateFormat.format(today);
System.out.println(formattedDate);
What I end up getting is "helmikuutata". I would expect "helmikuu" or "helmikuuta", but this just seems wrong.
Is this valid Finnish, or is there a bug in Java? My version is 1.8.0_31
Yes, this was a bug in JDK (See JDK-8074791), wherein an extra 'ta' was appended to the month name. This got fixed from JDK 8u60 version onwards. So, if you upgrade to latest JDK versions like JDK8u131, you will get the correct output.
I am convinced that the answer by Pallavi Sonal is correct. I have already upvoted it and you should probably accept it. I had wanted to keep the following a comment, but it deserves better formatting, so here goes.
java.time
Since you are using Java 8 (and even if you didn’t), you will prefer the modern more programmer friendly API of java.time:
LocalDate today = LocalDate.of(2017, Month.FEBRUARY, 1);
DateTimeFormatter dateFormat = DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG)
.withLocale(finLocale);
String formattedDate = today.format(dateFormat);
On my Java 1.8.0_131 it gives the expected
1. helmikuuta 2017
If someone reading this is using Java 6 or 7, please consider getting the ThreeTen Backport library so you can use the modern date and time API as shown.
This question already has answers here:
Java 8 LocalDateTime is parsing invalid date
(5 answers)
Closed 6 years ago.
Either I don't quite grasp what the resolver style in java.time does, or there is a bug.
I have the following code (in Scala):
import java.sql.Timestamp
import java.time.format.{DateTimeFormatter, ResolverStyle}
import java.time.ZonedDateTime
val str = "2016-07-11T05:45:44.552+04:00"
val iso1 = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSXXXXX")
val iso2 = iso1.withResolverStyle(ResolverStyle.STRICT)
Timestamp.from(ZonedDateTime.parse(str, iso1).toInstant) // works fine
Timestamp.from(ZonedDateTime.parse(str, iso2).toInstant) // nope!
The first version works and the second throws the following exception a java.time.format.DateTimeParseException. What I don't understand is why. The date and time are in my opinion valid.
See: https://docs.oracle.com/javase/8/docs/api/java/time/format/ResolverStyle.html#STRICT
This is incorrect ISO format, just use DateTimeFormatter.ISO_DATE_TIME.
I've made a jar for parsing a dateformat from text for JRE and Android.
Mostly It worked well. but when I try to parsing the following Chinese chars, It fails on Android and works on JRE. '五月' is May in Chinese.
"06 五月 2014"
I used the following code to parse it
String input = "06 五月 2014"
SimpleDateFormat df = new SimpleDateFormat("dd MMM yyyy", Locale.CHINESE);
Date date = df.parse(input);
So, i started narrowing down the problems and got the following test cases.
on Android,
DateFormatSymbols dfs = new DateFormatSymbols(Locale.CHINA);
String[] months = dfs.getMonths();// months[0] = 1月, months[1] = 2月 ...
String[] ampm = dfs.getAmPmStrings(); // ampm[0] = AM ampm[1] = PM
on JRE 1.7,
DateFormatSymbols dfs = new DateFormatSymbols(Locale.CHINA);
String[] months = dfs.getMonths();// months[0] = 一月, months[1] = 二月 ...
String[] ampm = dfs.getAmPmStrings(); // ampm[0] = 上午 ampm[1] = 下午
Why this happens? is this normal operation or am i missing something ?
Ignoring the difference between Java and Android, your code is not even guaranteed to work on different Java VMs. The API documentation does not cover a formal specification of the different date formatters and you are not guaranteed that the formatted output from one Java VM can be parsed by another Java VM.
In this case, the localization database in the Oracle VM uses "五月" as the Chinese word for the month of May (literary: "fifth moon"). Your Android localization database uses "5月" (literary: "5th moon"), which is just as correct, but different.