3
$\begingroup$

I'm trying to call a method on a java object that takes a single boolean argument - note boolean (native or primative) not Boolean (Object or Reference type).

object@method[True]

Goes bang with...

Java::argx1: Method named method defined in class blah.blah.blah.Object was called with an incorrect number or type of arguments. The argument was True.

Various experiments with MakeJavaObject fail for the obvious reason they build True on the Mathematica side of JLink.

$\endgroup$
2
  • $\begingroup$ You may try tocall Boolean.TRUE $\endgroup$
    – s.s.o
    Sep 16, 2014 at 18:36
  • $\begingroup$ @Ymareth Can you look at the latest edit of my answer and specify which operating system you are working on? $\endgroup$
    – halirutan
    Sep 1, 2016 at 10:56

1 Answer 1

1
$\begingroup$

Let's make a test by ourselves. The class java.lang.Boolean has a static method

public static String toString(boolean b)

that takes a primitive boolean and returns a string. Here we go:

<< JLink`
LoadJavaClass["java.lang.Boolean"]

and now

Boolean`toString[True]
(* "true" *)

So my educated guess is that your method does not take a single argument as the warning already tells you.

Aftermath

I considered this a simple mistake of the OP, but @Picket gave a minimal example in a comment, that fails on his machine

JLink Fail

I took the time to download the JSoup library and tried it myself. Mysteriously, it works on my machine

JLink no fail

One explanation is the difference in operating systems. While Picket is using OS X, I'm working on Linux here. I tried the above example in Mathematica version 11.

$\endgroup$
3
  • $\begingroup$ I have the same problem as the OP: screenshot. I have no problems with any of the other ~40 methods that I've used from jsoup, and this is the only one with a boolean. Is your minimal example really conclusive? Could there not be problems introduced with overloaded methods for example, which I suppose are more difficult for JLink to handle? $\endgroup$
    – C. E.
    Sep 1, 2016 at 0:18
  • $\begingroup$ @C.E. Hmm, strange. I just tried a non-trivial example with Matcher but it worked. Do we find an example that works in a standard java (without Jsoup)? Can you, just for for fun create a string object for your first argument? Like s = JavaNew["java.lang.String", "this is a string"]. $\endgroup$
    – halirutan
    Sep 1, 2016 at 0:42
  • $\begingroup$ That didn't work. I will try to reproduce the problem without jsoup tomorrow. $\endgroup$
    – C. E.
    Sep 1, 2016 at 0:50

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.