-1

I'm attempting to work with jsoup in RPGLE, but I don't know a lot about Java. I can't get past trying to create a java.io.File object to use in jsoup. I'm obviously doing something wrong, but I just can't seem to figure out what.

Here's my code:

       // Create Java String Object
       Dcl-Pr newString Object(*Java:'java.lang.String')
                        ExtProc(*Java:'java.lang.String':*CONSTRUCTOR);
         *N Varchar(32767) Const;
       End-Pr;

       // Create Java File Object
       Dcl-Pr newFile Object(*Java:'java.io.File')
                      ExtProc(*Java:'java.io.File':*CONSTRUCTOR);
         *N Object(*Java:'java.lang.string');
       End-Pr;

       Dcl-S String Object(*Java:'java.lang.string');
       Dcl-S File Object(*Java:'java.io.File');

       String = newString('/java/jsoup/46525580.html');
       File = newFile(String);

The String object is created successfully. I verified that using String.getBytes and returning the data back into an alpha field. However, the newFile call throws an RNQ0301 error message:

Message . . . . :   Java exception received when calling Java method (C G D   
  F).                                                                         
Cause . . . . . :   RPG procedure JSOUP in program RLSTESTLIB/JSOUP received  
  Java exception "java.lang.NoSuchMethodError:                                
  java/io/File.<init>(Ljava/lang/string;)V" when calling method "<init>" with 
  signature "(Ljava.lang.string;)V" in class "java.io.File".                  

What am I doing wrong here? The prototype I created for the java.io.File constructor is obviously wrong, but I'm not familiar enough with Java to figure it out.

Rob Schember
  • 206
  • 1
  • 3
  • 3
    *String* is written with a lowercase s twice in your code, that's the problem I think, because java names are case sensitive – nfgl Aug 24 '23 at 14:44
  • @nfgl -- ugh, that is absolutely maddening. I stared at this code for hours. Uppercasing the 2 incorrect "string"s fixed the problem. Thank you. – Rob Schember Aug 24 '23 at 15:42

1 Answers1

0

@nfgl is correct, the class ‘String’ needs to start with an uppercase S.

As a side note, that error is usually the result of a classpath error.

Suggestion: rather than put a lot of Java calls in your RPG code, create a single Java class (in RDi) to perform the detailed operations. Then just invoke that Java from the RPG.

David G
  • 3,940
  • 1
  • 22
  • 30