java.lang.String cannot be cast to [Ljava.lang.CharSequence;

3,249 views
Skip to first unread message

prhlava

unread,
Apr 16, 2009, 2:25:41 PM4/16/09
to Clojure

Hello,

I am trying to use a java library ( http://code.google.com/p/webdriver/
), the method I need to call has signature:

sendKeys(java.lang.CharSequence... keysToSend)

If I give it a clojure string, the "cannot be cast" message appears in
the stack trace.

I have tried explicit (cast java.lang.CharSequence "my-string") but
the cast does only "compare" AFAIK.

Is there a way to give the library what it wants from Clojure?

Kind regards,

Vlad

Kevin Downey

unread,
Apr 16, 2009, 2:35:24 PM4/16/09
to clo...@googlegroups.com
I would be interested in seeing a full stack trace and some pastbined
code. there are no clojure strings, just java strings, and java
strings are charsequences.
--
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

Paul Stadig

unread,
Apr 16, 2009, 2:41:31 PM4/16/09
to clo...@googlegroups.com
Are you trying to give it a string, or an array of strings?

sendKeys takes a variable number of arguments. The error you are getting is that it can't cast a java.lang.String into [Ljava.lang.CharSequence, where the '[' at the beginning of the type means an array. It is telling you that it cannot convert a String into an array of CharSequences. Maybe it will work with (into-array ["string"])?


Paul

prhlava

unread,
Apr 16, 2009, 3:03:47 PM4/16/09
to Clojure

Hello Paul,

> Are you trying to give it a string, or an array of strings?
> Maybe it will work with (into-array ["string"])?

Thank you, this was spot on, the correct call looks like:

(. query (sendKeys (into-array ["my-string"])))

Cheers!

Vlad

PS: Embarassingly, the hint is also in the FAQ...
Reply all
Reply to author
Forward
0 new messages