javaibm-midrangerpglerpgfreeform

Call java method from RPGLE (as400)


I need to call a java method from RPGLE, Im getting following error. I think the way I did prototype the method is wrong.

    Cause . . . . . :   RPG procedure TESTJ in program TESTLIB/TESTJ received 
  Java exception "java.lang.NoSuchMethodError:                             
  NumberToWord.strconvert([B)Ljava/lang/String;" when calling method       
  "strconvert" with signature "([B)Ljava.lang.String;" in class            
  "NumberToWord". 

My java code works fine. code is something like below,

public class NumberToWord
{
 .....
  .
   .
   public static String strconvert(String nms) {
    .
    .
    .
    return nms;
   }

}

My RPGLE code, which should be wrong is this,

  /free

   ctl-opt  dftactgrp(*no) actgrp(*caller);

   dcl-s String1 object(*java:'java.lang.String');
   dcl-s String2 object(*java:'java.lang.String');
   dcl-s str varchar(250);
   dcl-s JAVA_String object( *JAVA :'java.lang.String' );   


   dcl-pr JAVA_toString like( JAVA_String )
                        extproc( *JAVA :
                                 'java.lang.String' :
                                 *constructor );
   value varchar( 65535 ) const;
   end-pr;


   dcl-pr getNMTW static like( JAVA_String )
                        extproc( *JAVA :
                                 'NumberToWord' :
                                 'strconvert' );
   value varchar(65535) const;
   end-pr;


   dcl-pr getBytes char(250) extproc(*java:'java.lang.String':'getBytes');

   end-pr; 



   String1 = JAVA_toString('543');  //works fine

   str = getBytes(String1);         //works fine

   String2 = getNMTW('12345');      //exception occurs at this point

   str = getBytes(String2);

   *INLR = *ON;

 /END-FREE

JAVA_toString and getBytes methods work fine, when debug, exception occurs at getNMTW function.

CLASSPATH is already set. I think its fine since i'm getting NoSuchMethodError instead of NoClassFound error.


Solution

  • I found the error.

    when JVM has already started, the changes does not recognize by Java in that job I have to sign off and sign back on again to see the changes I made to the java function.

    http://www.ibm.com/developerworks/rational/cafe/docBodyAttachments/2681-102-2-7220/Troubleshooting_RPG_Calls_To_Java_v2.html#changeclasses