0

In R 3.3.3, using the package rJava (version 0.9-9), running on Linux (RHEL 6.9), I am encountering an error running the following piece of code to create a Java Date from an R string:

library(rJava)

rDateString <- "2016-01-01 10:00:00"

.jinit()
df <- .jnew("java/text/SimpleDateFormat", "yyyy-MM-dd HH:mm:ss")
pp <- .jnew("java/text/ParsePosition", as.integer(0))
d <- .jcall(df, "Ljava/util/Date", "parse", rDateString, pp)

This gives the following error:

Error in .jcall(df, "Ljava/util/Date", "parse", rDateString, pp) : 
  method parse with signature (Ljava/lang/String;Ljava/text/ParsePosition;)Ljava/util/Date not found

This confuses me, because this method should be available. Calling .jmethods on my SimpleDateFormat object, results in (snip):

> .jmethods(df)
 [5] "public java.util.Date java.text.SimpleDateFormat.parse(java.lang.String,java.text.ParsePosition)"  

So, as far as I can tell, I'm complying to the parse method signature, yet there is still an error. Can anyone shed some light as to what I am missing here? Much appreciated.

1 Answer 1

0

Missing semicolon (Ljava/util/Date => Ljava/util/Date;):

d <- .jcall(df, "Ljava/util/Date;", "parse", rDateString, pp)
d
[1] "Java-Object{Fri Jan 01 10:00:00 CET 2016}"
Sign up to request clarification or add additional context in comments.

1 Comment

Brilliant! It's always the little things... Thanks a bunch.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.