0

I'm trying to use an MPD library in Java in Clojure. Everything has gone well, but these methods that return a java.util.Collection get bad reception in REPL. Let's define

(def mpd (org.bff.javampd.MPD. "localhost" ))
(def pl (.getMPDPlaylist mpd))
(def db (.getMPDDatabase mpd))

And now some methods play ok:

(.getSongList pl) ; returns List<MPDSong>

works well. But for instance every db (MPDDatabase) method return Collection<MPDSong> (according to their API):

(.findAlbum db "Crises") ; returns Collection<MPDSong>
java.lang.ClassCastException (NO_SOURCE_FILE:0)

Doesn't work that well. Why is that, how to fix it?

Stack trace follows:

hello.hello=> (.findAlbum db "Crises")
java.lang.ClassCastException (NO_SOURCE_FILE:0)
hello.hello=> (.printStackTrace *e)
java.lang.ClassCastException (NO_SOURCE_FILE:0)
    at clojure.lang.Compiler.eval(Compiler.java:5440)
    at clojure.lang.Compiler.eval(Compiler.java:5391)
    at clojure.core$eval.invoke(core.clj:2382)
    at clojure.main$repl$read_eval_print__5624.invoke(main.clj:183)
    at clojure.main$repl$fn__5629.invoke(main.clj:204)
    at clojure.main$repl.doInvoke(main.clj:204)
    at clojure.lang.RestFn.invoke(RestFn.java:422)
    at user$eval13$acc__808__auto____14$fn__16.invoke(NO_SOURCE_FILE:1)
    at clojure.lang.AFn.run(AFn.java:24)
    at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.ClassCastException
    at java.lang.Class.cast(Class.java:2990)
    at clojure.lang.Reflector.boxArg(Reflector.java:364)
    at clojure.lang.Reflector.boxArgs(Reflector.java:397)
    at clojure.lang.Reflector.invokeMatchingMethod(Reflector.java:55)
    at clojure.lang.Reflector.invokeInstanceMethod(Reflector.java:28)
    at hello.hello$eval44.invoke(NO_SOURCE_FILE:8)
    at clojure.lang.Compiler.eval(Compiler.java:5424)
    ... 9 more
nil
2
  • The actual source of the exception isn't clear from what you've posted. Try calling (.printStackTrace *e). Commented Nov 25, 2010 at 18:35
  • @Alex, oh thanks for that. I tried to find the way to print the trace to no avail. Iincluded Commented Nov 25, 2010 at 18:57

1 Answer 1

1

Looks like the API Documentation is invalid (checking using clojure.contrib.repl-utils):

user> (show MPDDatabase "findAlbum$")
===  public org.bff.javampd.MPDDatabase  ===
[ 1] findAlbum : Collection (MPDAlbum)

and you need to a intermediate MPDAlbum object:

user> (.findAlbum db (MPDAlbum. "Crisis"))
#<ArrayList []>
Sign up to request clarification or add additional context in comments.

1 Comment

Wow, never'd have guessed. I'm gonna write that guy an angry email about that. :) For you, double thanks for hinting at repl-utils and the answer.

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.