× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.




Barbara, Scott and Matt, thanks for the help. I did get it working.

Thanks again,
Jon> Date: Thu, 7 Feb 2008 16:11:02 -0600> From: rpg400-l@xxxxxxxxxxxxxxxx> To: rpg400-l@xxxxxxxxxxxx> Subject: Re: Calling Java from RPG> > Hi Jon,> > Java supports overloading. Overloading means that you can have multiple > Java methods (equiv to RPG subprocedures) that have the exact same name, > but have different parameters. In other words, you could have 2 > different Java methods named CGProCLI within the same object, and each > one can be called independently.> > How does that work? When the system looks up the Java method name, it > doesn't only look for the name itself, but it also looks for a > "signature". The signature is basically a code that describes the > parameters and return value of the method. Both the signature and the > method name have to match.> > Let's look at the error method you described:> > Java exception "java.lang.NoClassDefFoundError: CGProCLI" when> calling method "<init>" with signature "()V" in class> "CGProCLI".> > <init> means it's calling the constructor method (*CONSTRUCTOR in RPG).> Signature ()V means that it's trying to call a Java method which has a > return value of VOID (meaning nothing is returned), and that accepts no > parameters. If there were parameters, they'd be described in between > the parenthesis.> > However, when I look at your Java code, I see this:> > public CGProCLI(String host,int port,String user,String password)> > While that is a "void" method (it doesn't return anything) it certainly > DOES accept parameters. I'm telling you this so that you'll understand > the error message next time you get it. The error isn't that you > spelled the method name wrong -- it's that you aren't passing the right > parameters to it!!> > In Java, when you code a constructor method, you name the method the > same as the class it's a part of. That's how the Java compiler knows > that it's a constructor -- the names match.> > In RPG, when you call a constructor (which, again, is done when the > class & method names match) you don't code the method name on the > prototype. Instead, you supply *CONSTRUCTOR to tell it to call the > constructor method. RPG knows that constructors have the same name as > the class, you don't have to specify the class name.> > This seems to be where you went wrong. You decided to call it twice, > Once using *CONSTRUCTOR (but without any parms) and again with a method > name that matches the class name. So what happens?> > a) When you call the *CONSTRUCTOR one, it bombs because you didn't pass > the parameters, and it therefore can't find a class that has the right > name and parameters.> > b) The one that does call it with the correct class isn't reached > (because your program blows up) but if it were, it also wouldn't work > because you didn't use the special value *CONSTRUCTOR. (And, also, you > have an error in that you've defined the PORT as a string instead of an > integer)> > So this is what you need to do:> > a) Eliminate the superfluous CGConnect2> > b) Add the parameters that you placed on CGConnect2 to the original > new_CGConnect() prototype.> > c) Change the "port" parameter to an Integer (10i 0 by VALUE in RPG).> > I hope that helps you both understand what you need to do, and what the > error messages are trying to tell you.> > > > Jon S wrote:> > All,> > > > I this is my first attempt at calling Java from RPG and I am about to pull my hair out.> > I have a .jar for from a third party vendor that I am trying to communicate with named CGProCLI.jar.> > I tried my own directory at first but the .jar currently resides in the QIBM/UserData/Java400/ext directory and it’s my understanding that I don’t even need to set the class path to there as it’s a default, but I set the classpath anyway.> > I have spent quite some time reading and looking at various examples on the web and even created my own java program on the 400 and compiled it in above directory and got it to work. Every time I run this I get the dreaded java.lang.NoClassDefFoundError error. I have included my prototype, RPG, the java code from the third party and my errors. I am sure this is something really silly on my part, but any help would be appreciated.> > > > Thanks, Jon > > > > > > * Connect method> > D CGConnect S O CLASS(*JAVA:'CGProCLI')> > * Connect method> > D new_CGConnect...> > D PR Like(CGConnect)> > D ExtProc(*JAVA:'CGProCLI'> > D :*CONSTRUCTOR)> > D CGConnect2...> > D PR> > D ExtProc(*JAVA:'CGProCLI'> > D :'CGProCLI')> > * method parameters> > D host O Class(*JAVA:'java.lang.String')> > D Const> > D port O Class(*JAVA:'java.lang.String')> > D Const> > D login O Class(*JAVA:'java.lang.String')> > D Const> > D password O Class(*JAVA:'java.lang.String')> > D Const> > > > > > And finally the code:> > > > > > D Conn S like(CGConnect)> > *> > /Free> > shost = newString(%trim(host));> > sport = newString(%trim(port));> > slogin = newString(%trim(login));> > spassword = newString(%trim(password));> > > > Conn = new_CGConnect(); This is where it blows.> > > > RtnCode = CGConnect2(Conn:sHost:sPort+> > sLogin:sPassword);> > > > /End-Free> > > > The java code:> > > > public CGProCLI(String host,int port,String user,String password) throws CGProException {> > openStream(host,port);> > connect(user,password); > > }> > > > And the ever too popular error:> > > > Cause . . . . . : RPG procedure CG0001 in program GDSBILLBLD/CG0001 received> > Java exception "java.lang.NoClassDefFoundError: CGProCLI" when calling> > method "<init>" with signature "()V" in class "CGProCLI".> > > > When I run:> > > > echo $CLASSPATH | tr ":" "\n"> > > > I get:> > '.> > /QIBM/UserData/Java400/ext/CGProCLI.jar> > _________________________________________________________________> > Need to know the score, the latest news, or you need your Hotmail®-get your "fix".> > http://www.msnmobilefix.com/Default.aspx> > -- > This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list> To post a message email: RPG400-L@xxxxxxxxxxxx> To subscribe, unsubscribe, or change list options,> visit: http://lists.midrange.com/mailman/listinfo/rpg400-l> or email: RPG400-L-request@xxxxxxxxxxxx> Before posting, please take a moment to review the archives> at http://archive.midrange.com/rpg400-l.>
_________________________________________________________________
Need to know the score, the latest news, or you need your Hotmail®-get your "fix".
http://www.msnmobilefix.com/Default.aspx

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

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.