Help coderanch get a
new server
by contributing to the fundraiser
  • 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 ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

[Jess] Exchanging values between Java and Jess

Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I am developing a workflow agent in Jade, using Jess for reasoning, etc. But I'm facing a problem with the 'Value' class, in fetching values from Jess to my Java program.


(defrule rule
(and (a) (b))
(store RESULT 1)

(watch facts)
(watch all)

jess = new Rete();
try {
FileReader fr = new FileReader(jessFile);
Jesp j = new Jesp(fr, jess);
} catch (JessException re) { System.out.println(re); }

try {

jess.executeCommand("(assert (a))");
jess.executeCommand("(assert (b))");
Value v = jess.fetch("RESULT");;
int i = v.intValue(jess.getGlobalContext());
System.out.println("The answer is: " + i);;
} catch (JessException re) {

After compiling, error on executing is as follows:

==> Focus MAIN
==> f-0 (MAIN::initial-fact)
<== Focus MAIN
==> Focus MAIN
==> f-0 (MAIN::initial-fact)
==> f-1 (MAIN::a)
==> f-2 (MAIN::b)
==> Activation: MAIN::rule1 : f-1, f-2
FIRE 1 MAIN::rule1 f-1, f-2
<== Focus MAIN
*** Uncaught Exception for agent a1 ***
at examples.myjess.myBasicJessBehaviour.action(
at jade.core.behaviours.Behaviour.actionWrapper(Unknown Source)
at jade.core.Agent.mainLoop(Unknown Source)
at Source)
ERROR: Agent a1 died without being properly terminated !!!
State was 2

I know its probably a silly mistake, but I'm just beginning to use Jess, so can't quite figure it out.

Thanks and regards,
author and iconoclast
Posts: 24207
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
Hi Indira,

Welcome to JavaRanch!

"v" is going to be null, because you're asking for the Value object before you've fired the rules which will create it. You want to save the fetch() call until after the run(). When you run the code above, the third line will indeed give you a NullPointerException.
If somebody says you look familiar, tell them you are in porn. Or in these tiny ads:
We need your help - Coderanch server fundraiser
    Bookmark Topic Watch Topic
  • New Topic