From: <php...@li...> - 2006-10-08 17:35:56
|
Hello. I've been trying to figure this out for a few days now, and I'm so totally stuck that I really need to ask for help before I go nuts. I have a .jar file with the following information given in the documentation: ----------------------------------------- example.jar java.lang.Object | +- example.client.ExampleRequest Method: public static ExampleResult execute(java.lang.String ID, java.lang.String Name, java.lang.String PW, java.lang.String extraParam1, java.lang.String extraParam2, java.lang.String extraParam3) ----------------------------------------- ... and the installation instructions say it needs to go here: /opt/example/lib/ Question: How do I call the execute() method and pass it the parameters it needs? I always get "java.lang.NoSuchMethodException" even though the method definitely exists. Is it because I'm not calling it correctly? 1) If my PHP code is this: java_require("/opt/example/lib/example.jar"); $example = new Java("example.client.ExampleRequest"); $result = $example->execute('123', 'John Doe', 'myPassword'); I get this in the Error log: java.lang.NoSuchMethodException: execute(o(Request$PhpParserString), o(Request$PhpParserString), o(Request$PhpParserString)). Candidates [public static example.client.ExampleRequest.execute(java.lang.String,java.lang.String,java .lang.String)] at php.java.bridge.JavaBridge.Invoke(JavaBridge.java:1007) at php.java.bridge.Request.handleRequest(Request.java:467) at php.java.bridge.Request.handleRequests(Request.java:493) at php.java.bridge.JavaBridge.run(JavaBridge.java:209) at php.java.bridge.ThreadPool$Delegate.run(ThreadPool.java:29) [client 123.456.789.012] PHP Warning: java.lang.Exception: Invoke failed: [c(ExampleRequest)]->execute(o(Request$PhpParserString), o(Request$PhpParserString), o(Request$PhpParserString)). Cause: java.lang.NoSuchMethodException: execute(o(Request$PhpParserString), o(Request$PhpParserString), o(Request$PhpParserString)). Candidates [public static example.client.ExampleRequest.execute(java.lang.String,java.lang.String,java .lang.String)] in /var/www/html/test.php on line 3 2) Or if I try this in my PHP: java_require("/opt/example/lib/example.jar"); $example = new Java("example.client.ExampleRequest"); $id = new Java('java.lang.String', '123'); $name = new Java('java.lang.String, 'John Doe'); $pw = new Java('java.lang.String', 'myPassword'); $result = $example->execute($id, $name, $pw); This code gives the same error message, except that o(Request$PhpParserString) is replaced with o(String). Can anyone see what I'm doing wrong? Thanks. -Kevin |
From: <php...@li...> - 2006-10-09 15:44:56
|
Hi Kevin, first of all thank you very much for the bug report. There is something I don't understand, the prototype definition you've given requires 6 arguments, but you've passed only 3: > public static ExampleResult execute(java.lang.String > ID, java.lang.String > Name, java.lang.String PW, java.lang.String > extraParam1, java.lang.String > extraParam2, java.lang.String extraParam3) > ->execute('123', 'John Doe', 'myPassword') However the error message lists the three param proc as a candidate, so your code should work. Can you please open a problem report (please use http://sourceforge.net/tracker/?func=add&group_id=117793&atid=679233) and set the java.log_level to 6, re-start the backend and append the log at the end of the ticket? The log will show the reason why the bridge has discarded the potential candidate. Regards, Jost Boekemeier ___________________________________________________________ Telefonate ohne weitere Kosten vom PC zum PC: http://messenger.yahoo.de |
From: <php...@li...> - 2006-10-10 13:14:49
|
Hi, Jost. Thanks for your tremendous contributions to the PHP and Java user communities. Your reply actual gave me the answer to my problem. Lately I've gotten used to using PHP functions with pre-defined default values for arguments that are not specified when the function is called. The Java method I was trying to call had a few optional parameters, and I just left them off, foolishly thinking they would get filled in by default... and that was causing the error. Once I gave it all the parameters it expected, it worked fine. Silly mistake! Once I overcame that, I had another problem which I'll outline here for posterity: I couldn't get the "java.class.path" value defined properly until I came across these two bits you posted in 2005: "According to the README it is java.classpath" and "Please don't forget the double-quotes" http://www.thescripts.com/forum/thread11467.html "java.classpath" vs. "java.class.path" -- There's probably a lot of confusion about this since http://php.net/java states it as "java.class.path" but apparently JavaBridge requires "java.classpath" Leaving off the quotes might be another common problem since lots of settings in php.ini don't require them -- for example setting extension_dir. But java.classpath didn't work for me until I added the quotes. Thanks again. -Kevin |