This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Other Java Products and Servers and the fly likes Using java object in LHS of a Jess rule  failed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Products » Other Java Products and Servers
Bookmark "Using java object in LHS of a Jess rule  failed" Watch "Using java object in LHS of a Jess rule  failed" New topic
Author

Using java object in LHS of a Jess rule failed

Hope Zhu
Ranch Hand

Joined: May 11, 2004
Posts: 32
Hi,

I try to use a property of a javabean in LHS of a rule, it failed with an error message "Can't call method on nil reference: size.". Below is my code. Anyone knows what I did wrong or how should I do it please please help.

public class JessData {
private ArrayList list;

public void setList(ArrayList lst) {
list = lst;
}

public ArrayList getList() {
return list;
}
...
}

In Jess:

(import java.util.*)
(defclass data JessData)
(bind ?x (new JessData))
(definstance data ?x static)

(defrule test_rule
(data (list ?y&: (> (?y size) 0)))
=>
(printout t "test_rule fired" crlf))

I also tried using (test (> (?y size) 0)) I got the same error.

Thanks a lot in advance.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

The message (which would have included some more information on subsequent lines) says that you asked Jess to call the method "size" on a nil (i.e., null) reference. Therefore ?y is apparently null. Looking at the code for the "JessData" object, it looks as though the "list" property starts out as null, and doesn't become non-null until somebody calls setList() (which never happens here.)

I believe that the JavaBeans spec prohibits properties from having null values. Jess will allow it, but of course if you actually try to access the null property, as here, there may be problems.
[ September 17, 2004: Message edited by: Ernest Friedman-Hill ]

[Jess in Action][AskingGoodQuestions]
Hope Zhu
Ranch Hand

Joined: May 11, 2004
Posts: 32
Thanks Ernest, the problem solved. Just as you said "the JavaBeans spec prohibits properties from having null values. Jess will allow it", so I added init for list in the javabean code, like
public class JessData {
private ArrayList list = new ArrayList(); ...
}
it works. You are great!
Thanks again.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using java object in LHS of a Jess rule failed
 
Similar Threads
Neef Help with Printing
Sudoku solver help (not brute force)
how this code is working?
outputing an arraylist of arraylists to a file.
ArrayList