This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Other Java Products and Servers and the fly likes how to set nil as a slotvalue from java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Products » Other Java Products and Servers
Bookmark "how to set nil as a slotvalue from java" Watch "how to set nil as a slotvalue from java" New topic
Author

how to set nil as a slotvalue from java

Hope Zhu
Ranch Hand

Joined: May 11, 2004
Posts: 32
Hi,

I wonder anyone here could help me to figure out how to set nil as a slot value from java.

I have a template in a .clp file define as below:

(deftemplate test1
(slot x)
(slot y (default nil))
(slot z (default nil))
)

Inside my java code I call Fact.setslotvalue and Rete.assertFact to do what I want. The problem is if I want to set null(java) to y or Z I always get null exception. I tried in jess enviorment it works fine, but why not from java?

Below is my java code snippet. If anyone knows why it did not work please help. Thanks in advance.

Rete eng = new Rete();
Fact testFact = new Fact("test1", eng);
testFact.setSlotValue("x", new Value(new Date()));
testFact.setSlotValue("y", null); //with or without this line I get exception, but different exception.
eng.assertFact(testFact);

By the way we use Jess 6.1P7.

Thanks
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

We talked about this via email, but I'll repeat the answer here just so no one thinks this question went unanswered: slots can't contain null, but they can instead contain the Jess constant 'nil'. You can use the static Java variable jess.Funcall.NIL for this:

testFact.setSlotValue("y", Funcall.NIL);

But in fact that's the default for a slot you don't specifically populate, so this really isn't necessary.


[Jess in Action][AskingGoodQuestions]
 
wood burning stoves
 
subject: how to set nil as a slotvalue from java