• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to set nil as a slotvalue from java

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic