• 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

[Jess] Exchanging values between Java and Jess

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

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.

myJessAgent.clp:

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

(watch facts)
(watch all)
(reset)
(run)

myBasicBehavior.java:

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

try {
jess.reset();

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

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 ***
java.lang.NullPointerException
at examples.myjess.myBasicJessBehaviour.action(myBasicJessBehaviour.java:67)
at jade.core.behaviours.Behaviour.actionWrapper(Unknown Source)
at jade.core.Agent.mainLoop(Unknown Source)
at jade.core.Agent.run(Unknown Source)
at java.lang.Thread.run(Thread.java:536)
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,
Indira.
 
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
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic