Passing a Byte into a Java method

53 views
Skip to first unread message

Brad Wood

unread,
Apr 27, 2015, 1:54:56 PM4/27/15
to lu...@googlegroups.com
I'm having issues passing a Byte into a Java library and I honestly can't find a single place on Google where anyone has done it or even talked about doing it.  I'm not sure if this means I'm missing something very simple and obvious or just the first person to try :)

Here is the java method I'm trying to call:

The method signature is quite simple:
public static native void shiftOut(byte dPin, byte cPin, byte order, byte val);

Using the CommandBox 2.0.0 REPL (Running Lucee 4.5.1.008):

CFSCRIPT-REPL: shift = createObject( 'java', 'com.pi4j.wiringpi.Shift')
[Object java.lang.Class]
CFSCRIPT-REPL: shift.shiftIn( 27, 28, shift.MSBFIRST, '00000000' )
ERROR
No matching Method for shiftIn(numeric, numeric, numericstring) found for com.pi4j.wiringpi.Shift
 
Ok, fair enough-- I didn't cast anything.  Lucee saw a numeric, numeric, numeric and a string, but we need all four of the parameters to be bytes.  Let's try casting the first parameter and see what happens.


CFSCRIPT-REPL: shift.shiftIn( javaCast( 'byte', 27 ), 28, shift.MSBFIRST, '00000000' )
ERROR
No matching Method for shiftIn(numeric, numeric, numeric, string) found for com.pi4j.wiringpi.Shift

Nope, the first param was still seem as a numeric even though I cast it.  Let's try manually creating an instance of java.lang.Byte.

CFSCRIPT-REPL: byte = createObject( 'java', 'java.lang.Byte')
[Object java.lang.Class]
CFSCRIPT-REPL: shift.shiftIn( byte.init( 27 ), 28, shift.MSBFIRST, '00000000' )
ERROR
No matching Method for shiftIn(numeric, numeric, numeric, string) found for com.pi4j.wiringpi.Shift

No dice.  Lucee is still convinced I'm trying to pass a "numeric" into my Java function. 

I won't show the code, but even trying to javaCast() my Byte object results in Lucee seeing a "numeric".  Also, I'm aware the "java.lang.Byte" is not the same as a native "byte" data type, but calling byte.init(27).byteValue() doesn't make any difference.  It's still always a numeric.

Any ideas?

Thanks!

~Brad

Brad Wood

unread,
Apr 27, 2015, 2:00:32 PM4/27/15
to lu...@googlegroups.com
Sigh, I stared at this all morning and even thought I double checked the method name, but it wasn't until about 2 minutes after hitting send that I realized I had been calling the wrong method.  Notice, my examples have "shiftIn" not "shiftOut"!  

Lol, working great now so I think this can be entirely disregarded.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp 

ColdBox Platform: http://www.coldbox.org 


--
You received this message because you are subscribed to a topic in the Google Groups "Lucee" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/lucee/4wQTYdmE6DQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to lucee+un...@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/7713fd26-ba04-43c6-b85b-3e35a2df8ae2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Michael Offner

unread,
Apr 27, 2015, 2:08:32 PM4/27/15
to lucee
i will do a test run myself, in my opinon this should work.

Micha


--
You received this message because you are subscribed to the Google Groups "Lucee" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+un...@googlegroups.com.

To post to this group, send email to lu...@googlegroups.com.

Brad Wood

unread,
Apr 27, 2015, 2:12:53 PM4/27/15
to lu...@googlegroups.com
Yes, it would be nice to know why the error didn't at least recognize that I was passing in "byte" or "Byte".  The "numeric" bit is what led me astray, thinking it was just a casting issue.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp 

ColdBox Platform: http://www.coldbox.org 


Reply all
Reply to author
Forward
0 new messages