From: <php...@li...> - 2008-03-04 22:04:27
|
I was trying to use the jFuzzyLogic toolkit with PHP/Java bridge but I got some error. The PHP/Java bridge I use is 5.1.0 and the jFuzzyLogic is 1.2.1. Here's my code: <?php if(!extension_loaded("java")) require_once("JavaBridge/java/Java.inc"); java_require("jFuzzyLogic_1_2_1.jar"); $fis = new Java("net.sourceforge.jFuzzyLogic.FIS"); $fis->load("fcl/tipper.fcl"); if( $fis == null ) { echo "<p>Can't load file</p>"; } else { echo "<p>Load succeed</p>"; } $fuzzyRuleSet = $fis->getFuzzyRuleSet("tipper"); if( $fuzzyRuleSet == null ) { echo "<p>Can't get fuzzy rule set</p>"; } else { echo "<p>Get fuzzy rule set succeed</p>"; } $temp = $fuzzyRuleSet->toString(); echo "<p>fuzzy rule set<br />" . $temp . "</p>"; ?> And the output is: Load succeed Get fuzzy rule set succeed Fatal error: Uncaught [[o:Exception]:"java.lang.Exception: Invoke failed: [[o:Request$PhpNull]]->toString. Cause: java.lang.NullPointerException: call object is null, check the server log file(s). VM: 1.5.0@http://www.ibm.com/" at: #-5 php.java.bridge.JavaBridge.Invoke(JavaBridge.java:1016) #-4 php.java.bridge.Request.handleRequest(Request.java:409) #-3 php.java.bridge.Request.handleRequests(Request.java:485) #0 C:\temp\Terry\xampp\htdocs\Thesis_Dexiong_Terry_Zhang\JavaBridge\java\Java.inc(259): java_ThrowExceptionProxyFactory->getProxy(4, 'php.java.bridge...', true) #1 C:\temp\Terry\xampp\htdocs\Thesis_Dexiong_Terry_Zhang\JavaBridge\java\Java.inc(411): java_Arg->getResult(true) #2 C:\temp\Terry\xampp\htdocs\Thesis_Dexiong_Terry_Zhang\JavaBridge\java\Java.inc(417): java_Client->getWrappedResult(true) #3 C:\temp\Terry\xampp\htdocs\Thesis_Dexiong_Terry_Zhang\JavaBridge\java\Java.inc(621): java_Client->getResult() #4 C:\temp\Terry\xampp\htdocs\Thesis_Dexiong_Terry_Zhang\JavaBridge\java\Java.inc(1749): java_Client->invokeMeth in C:\temp\Terry\xampp\htdocs\Thesis_Dexiong_Terry_Zhang\JavaBridge\java\Java.inc on line 222 According to the documentation, toString() is a legal method in the FuzzyRuleSet class and the jFuzzyLogic toolkit is tested in java and works fine. Does anyone know how come I get this error? Any help will be appreciated. Thanks a lot!!! Terry |
From: <php...@li...> - 2008-03-05 09:55:01
|
Hi, > if( $fis == null ) { The above test is invalid. $fis is an object representing Java NULL, not a PHP null pointer. Please re-read the NEWS file for version 5.0.0 or the PHP/Java Bridge documentation. Regards, Jost Boekemeier E-Mails jetzt auf Ihrem Handy. www.yahoo.de/go |
From: <php...@li...> - 2008-03-05 09:57:12
|
> > if( $fis == null ) { > > The above test is invalid. $fis is an object representing Java NULL, not a PHP null pointer. BTW: a PHP null value should be tested with is_null(...), see your PHP documentation Machen Sie Yahoo! zu Ihrer Startseite. Los geht's: http://de.yahoo.com/set |
From: <php...@li...> - 2008-03-07 04:09:57
|
Thanks for the help. But the if( $fis == null ) is not the cause of the error. The error is from $temp = $fuzzyRuleSet->toString(); Even I take out the null test, the error still remains. Can anyone help? Thanks! On Wed, Mar 5, 2008 at 1:57 AM, <php...@li...> wrote: > > > if( $fis == null ) { > > > > The above test is invalid. $fis is an object representing Java NULL, not a PHP null pointer. > > BTW: a PHP null value should be tested with is_null(...), see your PHP documentation > > > Machen Sie Yahoo! zu Ihrer Startseite. Los geht's: > http://de.yahoo.com/set > > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > php-java-bridge-users mailing list > php...@li... > https://lists.sourceforge.net/lists/listinfo/php-java-bridge-users > |
From: <php...@li...> - 2008-03-07 08:34:43
|
> if( $fuzzyRuleSet == null ) { > $temp = $fuzzyRuleSet->toString(); > > Even I take out the null test, the error still remains. Can anyone help? Thanks! The same argument applies to the above code, of course. Use (string)$fuzzyRuleSet == null or better is_null (java_values ($fuzzyRuleSet)) for the test. Regards, Jost Boekemeier Lesen Sie Ihre E-Mails auf dem Handy. www.yahoo.de/go |
From: <php...@li...> - 2008-03-07 16:49:23
|
Thank you! Yes, I understand that. Actually, I have already taken out the if statment if( $fuzzyRuleSet == null ) { so I am running $temp = $fuzzyRuleSet->toString(); directly, but it still give me an nullpointerexception. The method can run in java just don't understand how come it cannot run in php. Any other suggestions? Please! Thanks again! On Fri, Mar 7, 2008 at 12:34 AM, <php...@li...> wrote: > > if( $fuzzyRuleSet == null ) { > > > $temp = $fuzzyRuleSet->toString(); > > > > Even I take out the null test, the error still remains. Can anyone help? Thanks! > > The same argument applies to the above code, of course. > > Use > > (string)$fuzzyRuleSet == null > > or better > > is_null (java_values ($fuzzyRuleSet)) > > > for the test. > > > Regards, > Jost Boekemeier > > > > Lesen Sie Ihre E-Mails auf dem Handy. > www.yahoo.de/go > > ------------------------------------------------------------------------- > > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > php-java-bridge-users mailing list > php...@li... > https://lists.sourceforge.net/lists/listinfo/php-java-bridge-users > |
From: <php...@li...> - 2008-03-08 13:17:58
|
> Thank you! Yes, I understand that. No, I don't think so. :) Please read the error message and your code carefully. Regards, Jost Boekemeier Machen Sie Yahoo! zu Ihrer Startseite. Los geht's: http://de.yahoo.com/set |
From: <php...@li...> - 2008-03-08 13:48:16
|
> [[o:Request$PhpNull]]->toString. Instead of a NullPointerException we should throw a custom exception which explains that the user has passed a PHP null value to the bridge. Lesen Sie Ihre E-Mails auf dem Handy. www.yahoo.de/go |
From: <php...@li...> - 2008-03-08 17:05:46
|
Thanks again! I tried another approach and I guess I found the reason. Right now I put everything inside a java class and it runs in java with no problem. But once I try to run it in php, it fail to load the file. Here's how it looks like. Test1.java import net.sourceforge.jFuzzyLogic.FIS; import net.sourceforge.jFuzzyLogic.rule.FuzzyRuleSet; public class Test1{ private FIS aFIS; private FuzzyRuleSet aRuleSet; public Test1(){} public String init(){ String fileName = "tipper.fcl"; aFIS = FIS.load(fileName,true); if( aFIS == null ){ return "Can't load file: '" + fileName + "'"; } aRuleSet = aFIS.getFuzzyRuleSet(); if(aRuleSet == null){ return "Can't load rule set"; } return "Initialization succeed"; } public String setRule(double x, double y){ if(aRuleSet == null){ return "Can't access rule set"; } else{ aRuleSet.setVariable("service", x); aRuleSet.setVariable("food", y); aRuleSet.evaluate(); return "" + aRuleSet.getVariable("tip").defuzzify(); } } public String printRuleSet(){ if(aRuleSet == null){ return "Can't print rule set"; } else{ return aRuleSet.toString(); } } } test1.php <?php if(!extension_loaded("java")) require_once("JavaBridge/java/Java.inc"); java_require(".;jFuzzyLogic_1_2_1.jar;Test1.jar"); try{ $temp = new Java("Test1"); echo "<p>" . java_inspect($temp) . "</p>"; echo "<p>" . $temp->init() . "</p>"; echo "<p>" . $temp->setRule(3, 7) . "</p>"; echo "<p>" . $temp->printRuleSet() . "</p>"; } catch(JavaException $ex){ $exStr = java_cast($ex, "string"); echo "<p>Exception occured; mixed trace: " . $exStr . "</p>"; } ?> and the output [class Test1: Constructors: public Test1() Fields: Methods: public boolean java.lang.Object.equals(java.lang.Object) public native int java.lang.Object.hashCode() public java.lang.String java.lang.Object.toString() public java.lang.String Test1.init() public java.lang.String Test1.setRule(double,double) public java.lang.String Test1.printRuleSet() public final native java.lang.Class java.lang.Object.getClass() public final native void java.lang.Object.notify() public final native void java.lang.Object.notifyAll() public final void java.lang.Object.wait() throws java.lang.InterruptedException public final void java.lang.Object.wait(long) throws java.lang.InterruptedException public final native void java.lang.Object.wait(long,int) throws java.lang.InterruptedException Classes: ] Can't load file: 'tipper.fcl' Exception occured; mixed trace: java.lang.Exception: Invoke failed: [[o:Test1]]->setRule((o:double)[o:PhpExactNumber], (o:double)[o:PhpExactNumber]). Cause: java.lang.IllegalArgumentException VM: 1.5.0@http://www.ibm.com/ All files are sitting in the same directory. Any idea? Thanks On Sat, Mar 8, 2008 at 5:48 AM, <php...@li...> wrote: > > [[o:Request$PhpNull]]->toString. > > Instead of a NullPointerException we should throw a custom exception which explains that the user > has passed a PHP null value to the bridge. > > > > > Lesen Sie Ihre E-Mails auf dem Handy. > www.yahoo.de/go > > ------------------------------------------------------------------------- > > > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > php-java-bridge-users mailing list > php...@li... > https://lists.sourceforge.net/lists/listinfo/php-java-bridge-users > |
From: <php...@li...> - 2008-03-09 11:28:36
|
Hi, I am sorry, but I could not reproduce these problems. I have tested with IBM Java 1.5 on a Linux machine with the latest version of jFuzzyLogic. Everything works as expected. If you have any problems with the PHP/Java Bridge or its documentation, please open a problem report, please use http://sourceforge.net/tracker/?func=add&group_id=117793&atid=679233). > Thanks again! I tried another approach and I guess I found the reason. The reason why the procedure returns a NULL object is that the file could not be found in Java's current working directory (or class path). Since your NULL checks are completely wrong, they return false results and pretend that the file exists. > Right now I put everything inside a java class and it runs in java You don't need to write such a wrapper class. > public String setRule(double x, double y){ > echo "<p>" . $temp->setRule(3, 7) . "</p>"; > Can't load file: 'tipper.fcl' Correct. tipper.fcl is not in Java's working directory (or not accessible by the current class loader). > Exception occured; mixed trace: java.lang.Exception: Invoke failed: > [[o:Test1]]->setRule((o:double)[o:PhpExactNumber], > (o:double)[o:PhpExactNumber]). Cause: > java.lang.IllegalArgumentException VM: 1.5.0@http://www.ibm.com/ Please take a look at what you have passed and what is expected. setRule expects two double values, not two Integer values. In the end this may be a Java class loading issue. Since class loading is outside of the scope of the PHP/Java Bridge, this is not a PHP/Java Bridge problem. (Use the bug tracker, if you think this is a bug in the DynamicClassLoader. But I am quite certain that this will be closed, as dynamic class loading is not really possible in Java -- I'd rather like to remove java_require() instead.) It is debatable if the bridge should automatically convert an object into a boolean ($object==null) or to automatically convert an exact into an inexact number. But I think the error messages are okay: A NullPointerException means that you have passed NULL, which in turn means that some earlier call failed to produce a result. In this case the lookup for "tipper.tcl" failed. -- If you look at the log file, you see a clear error message ("tipper.tcl not found") from your library. The other problem is also obvious; if you pass an integer to a procedure expecting a double, you'll get an IllegalArgumentException. If there's anything we could do to improve the bridge or its documentation, please let us know. Regards, Jost Boekemeier Machen Sie Yahoo! zu Ihrer Startseite. Los geht's: http://de.yahoo.com/set |
From: <php...@li...> - 2008-03-09 16:29:15
|
Thanks Jost! I just solved the problem by specifying the absolute path of the file "tipper.fcl" in the fileName variable although the file is in the same directory. Now, everything works fine. Thanks again for all the help! Terry On Sun, Mar 9, 2008 at 4:28 AM, <php...@li...> wrote: > Hi, > > I am sorry, but I could not reproduce these problems. > > I have tested with IBM Java 1.5 on a Linux machine with the latest version of jFuzzyLogic. > Everything works as expected. > > If you have any problems with the PHP/Java Bridge or its documentation, please open a problem > report, please use http://sourceforge.net/tracker/?func=add&group_id=117793&atid=679233). > > > > Thanks again! I tried another approach and I guess I found the reason. > > The reason why the procedure returns a NULL object is that the file could not be found in Java's > current working directory (or class path). Since your NULL checks are completely wrong, they > return false results and pretend that the file exists. > > > > Right now I put everything inside a java class and it runs in java > > You don't need to write such a wrapper class. > > public String setRule(double x, double y){ > > echo "<p>" . $temp->setRule(3, 7) . "</p>"; > > > Can't load file: 'tipper.fcl' > > Correct. tipper.fcl is not in Java's working directory (or not accessible by the current class > loader). > > > > Exception occured; mixed trace: java.lang.Exception: Invoke failed: > > [[o:Test1]]->setRule((o:double)[o:PhpExactNumber], > > (o:double)[o:PhpExactNumber]). Cause: > > java.lang.IllegalArgumentException VM: 1.5.0@http://www.ibm.com/ > > Please take a look at what you have passed and what is expected. setRule expects two double > values, not two Integer values. > > In the end this may be a Java class loading issue. Since class loading is outside of the scope of > the PHP/Java Bridge, this is not a PHP/Java Bridge problem. (Use the bug tracker, if you think > this is a bug in the DynamicClassLoader. But I am quite certain that this will be closed, as > dynamic class loading is not really possible in Java -- I'd rather like to remove java_require() > instead.) > > > It is debatable if the bridge should automatically convert an object into a boolean > ($object==null) or to automatically convert an exact into an inexact number. But I think the > error messages are okay: A NullPointerException means that you have passed NULL, which in turn > means that some earlier call failed to produce a result. In this case the lookup for "tipper.tcl" > failed. -- If you look at the log file, you see a clear error message ("tipper.tcl not found") > from your library. > > The other problem is also obvious; if you pass an integer to a procedure expecting a double, > you'll get an IllegalArgumentException. > > If there's anything we could do to improve the bridge or its documentation, please let us know. > > > Regards, > Jost Boekemeier > > > > > > > > > > > Machen Sie Yahoo! zu Ihrer Startseite. Los geht's: > http://de.yahoo.com/set > > ------------------------------------------------------------------------- > > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > php-java-bridge-users mailing list > php...@li... > https://lists.sourceforge.net/lists/listinfo/php-java-bridge-users > |