|
An RPG string is not compatible with a Java String object. To pass a string from RPG to Java, you must do one of two things: 1. In the RPG, create a prototype to call the Java String constructor to create a Java String object and then pass that object to your Java method. 2. In the Java, define that field as a byte array and then create a Java String object from the byte array in the Java method. The latter is much more efficient, and you don't leave any Java String objects about that the Java garbage collector can not collect. Also, convert any String objects being returned from Java to RPG to a byte array before returning. That way the String object can be garbage collected. If you pass the String object back, you have to send the object back into the Java getBytes method to convert it into a byte array, which RPG can use. I have implemented this byte array usage, and volume tested the process with hundreds of thousands of repetitions and there was no slow down. Making three calls into Java, the first to call the String constructor, the second to call your method, and finally to use getBytes to convert the String back, will slow down very quickly. Bill -----Original Message----- From: Roman Prigozhin [mailto:Roman.Prigozhin@xxxxxxxxxxxxxxx] Sent: Tuesday, March 30, 2004 7:51 PM To: 'java400-l@xxxxxxxxxxxx' Subject: Calling JAVA from RPG ( passing string variable ) I'm trying to call my java methods from RPG, everything works but passing string variables. Probably I have some issues with data conversion. Error I'm getting is : Message . . . . : Java exception received when calling Java method (C G D F). Cause . . . . . : RPG procedure TEST in program ROMAN/TEST received Java exception "java.lang.NoSuchMethodError: testStuff" when calling method "testStuff" with signature "([B)I" in class "MyClass". But prototype of the java function is correct : Compiled from MyClass.java public class MyClass extends java.lang.Object public MyClass(); /* ()V */ public static int testStuff(byte[]); /* ([B)I */ Here is my java class : public class MyClass { public static int testStuff( byte[] test ){ int size =0; size = test.length; return size; } } Here is the Prototype : D testStuff PR 10i 0 ExtProc(*JAVA: D 'MyClass': D 'testStuff') D Static D teststr 30A And here is the RPG programm : H DftActGrp(*NO) ActGrp(*CALLER) /Copy *LibL/RPGSRC,TEST1PR D first S 10i 0 Inz(23) D second S 10i 0 Inz(18) D sum S 10i 0 D testStr S 30A /Free // call my home grown method testStr = 'roman'; sum = testStuff(testStr); Dsply testStr; /End-Free Thanks, Roman www.aadt.com
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.