I think that Calvin wrote:
>>...it throws null pointer exception of variable Result. PLease advice.

Hi Calvin,

I stripped down your example (merlinMain doesn't seem to supply anything but
a Rete instance -- and an oddly public one at that) and added a try/catch
block to intercept any Jess exceptions.  Sure enough, Jess complained:

Jess reported an error in routine Context.getVariable
        while executing (assert (MAIN::adv-type ?x)).
  Message: No such variable x.
  Program text: ( assert ( adv-type ?x ) )  at line 1.

In your line ... (assert (adv-type ?x)) the variable ?x will not be bound to
anything until the rule (defrule r-adv-type-ask) fires, hence the null
pointer on the fact assertion.

This also indicates that there is something not quite right in your
backward-chaining implementation, too.  Ernest might give you the whole
answer here, but see if you can figure it out first.  If not, just repost
from where you get stuck.

FWIW - Again, my advice to beginners (based on bitter experience) is always
to become proficient with the Jess language via the command line before
adding another layer of complexity to one's study by programming the Jess
API.

If you run this class in your debugger, you'll see clearly where your code
blows up.

==========================================

import jess.*;

public class TestBug {

    private Rete r;

    public TestBug() {
        this.r = new Rete();
    }

    public static void main(String[] args) {
        TestBug tb = new TestBug();
        tb.run();
    }

    public void run() {

        try {
            r.clear();
            r.executeCommand("(do-backward-chaining r-adv-type)");

            r.executeCommand("(defrule r-adv-type"
                    + "(need-adv-type ?x ?)"
                    + "(adv-attr target audience demographically)"
                    + "(adv-attr suitable to market time frame sensitive
product)"
                    + "=>"
                    + "(assert (adv-type radio-advertisement radio)))");

            r.executeCommand("(defrule r-adv-type-ask" + "(adv-type-ask)"
                    + "(adv-type ?x ?y)" + "=>" + "(store result ?x))");

            r.reset();

            r.executeCommand("(assert (adv-attr target audience
demographically))");
            r.executeCommand("(assert (adv-attr suitable to market time
frame sensitive product))");
            r.executeCommand("(assert (adv-type-ask))");
            r.executeCommand("(assert (adv-type ?x))"); // offending line

            r.run();

            Value va = r.executeCommand("(facts)");
            String str1 =
r.fetch("result").stringValue(r.getGlobalContext());
            System.out.println("----" + str1);
        }

          // This is the important part! :-D
        catch (JessException jex) {
            jex.printStackTrace(System.err);
        }
    }
}
==========================================


Cheers,
-JM
------------------------

Jason Morris
Morris Technical Solutions
[EMAIL PROTECTED]
www.morristechnicalsolutions.com
fax/phone: 503.692.1088

--------------------------------------------------------------------
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]
--------------------------------------------------------------------

Reply via email to