Hi

On Thu, Nov 20, 2008 at 12:10 AM, Chouser <[EMAIL PROTECTED]> wrote:
>
> On Wed, Nov 19, 2008 at 4:00 AM, Michael Wood <[EMAIL PROTECTED]> wrote:
>>
>> Exception in thread "main" java.lang.IllegalArgumentException: No
>> matching method found: getString for class
>> org.dcm4che2.data.BasicDicomObject (dinfo.clj:0)
>
> This was discussed on IRC:
>
> http://clojure-log.n01se.net/date/2008-11-19.html#15:46a-16:07
>
> So it looks like there may be no good, general, solution.  Unless or
> until there is, there's a work-around using reflection manually.
>
> Start by getting a reference to the Method you're trying to call:
>
> (def bdo-get-string (.getMethod (identity BasicDicomObject)
> "getString" (into-array [Integer/TYPE])))

Thanks.  That works fine.  I'll use that in the mean time.

> The three args to .getMethods are:
> 1. The class (use identity to get the instance of Class instead of
> trying to BasicDicomObject's non-existent getMethod method)
> 2. The name of the method as a string, "getString"
> 3. An array of the argument types for the method you want to call.
> Use Interger/TYPE to specify the primitive 'int'
>
> You can then call the method you found above using the .invoke method
> of the Method instance:
>
> (.invoke bdo-get-string (BasicDicomObject.) (to-array [0x00100010]))
>
> The .invoke method always takes 3 args:
> 1. The Method instance we got earlier
> 2. The instance of the class you want call (in this example I created
> a new instance on the spot)
> 3. And array holding all the args to pass to the Method.

Thanks for the explanation.

> Not too pretty, but of course if you find you actually need this you
> can wrap either step in a function to make calling it more pleasant.

Yes, I've changed print-tag from:

(defn print-tag [dcm tag]
 (.getString dcm tag))

to:

(defn print-tag [dcm tag]
 (def bdo-get-string
  (.getMethod
   (identity BasicDicomObject) "getString" (into-array [Integer/TYPE])))
 (.invoke bdo-get-string dcm (to-array [tag])))

-- 
Michael Wood <[EMAIL PROTECTED]>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to