How to call a java method that takes a boolean (not Boolean)?

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.

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

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


and now

BooleantoString[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

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

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.

• 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? – C. E. Sep 1 '16 at 0:18
• @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"]. – halirutan Sep 1 '16 at 0:42
• That didn't work. I will try to reproduce the problem without jsoup tomorrow. – C. E. Sep 1 '16 at 0:50