Hi Ryan,
The code shown here is pretty close. I see two things wrong with it.
First, the store.clp file contains the definition of a global and of a
rule, but it doesn't do anything about firing the rule; so after
calling (batch), those two things are defined, but the right-hand-side
of the rule hasn't been executed. Adding (run) to the end of
store.clp, or calling r.run() in main() after the executeCommand()
call, would run the rule and therefore execute the store command.
Second, the String used to fetch the result ("xmlResult") doesn't
match the one used to store it ("Result"). The two have to match
exactly. Any number of datums can be store simultaneously, each under
its own name.
I think Ryan G. Beckes (Home) wrote:
> Hello,
>
> I am trying to call a clips file, store a string in the clips file and
> then fetch it in my java code. I get a null pointer exception when running
> FetchVal.
>
> Ryan
>
> Java code
> import jess.*;
> public class FetchVal
> {
> public static void main(String[] unused) throws JessException
> {
> Rete r = new Rete();
> r.executeCommand("(batch store.clp)");
> Value v = r.fetch("xmlResult");
> System.out.println(v.stringValue(r.getGlobalContext()));
>
> }
> }
>
> JESS code (store.clp)
> (defglobal ?*Result* = (new java.lang.String))
>
> (defrule initialize
> =>
>
> (bind ?*Result* "stuff")
> (store "Result" ?*Result*)
> )
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
> in the BODY of a message to [EMAIL PROTECTED], NOT to the
> list (use your own address!) List problems? Notify [EMAIL PROTECTED]
> ---------------------------------------------------------------------
>
---------------------------------------------------------
Ernest Friedman-Hill
Distributed Systems Research Phone: (925) 294-2154
Sandia National Labs FAX: (925) 294-2234
Org. 8920, MS 9012 [EMAIL PROTECTED]
PO Box 969 http://herzberg.ca.sandia.gov
Livermore, CA 94550
---------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the
list (use your own address!) List problems? Notify [EMAIL PROTECTED]
---------------------------------------------------------------------