The Jess error messages that start with "Jess reported an error in
routine X" will always go on to provide an actual error message; here
I think it would be "Called routine threw an exception." Then if you
called getCause() on the JessException (I talk about this in the
manual, section 10.2), you'd get the actual exception, which is thrown
from your code. When Jess calls CurrentEvent.getReading(), there's a
NullPointerException because the BeanSimulator member "bs" is null,
having never been initialized.
If you're not familiar with the practice of "unit testing", check out
this page: http://en.wikipedia.org/wiki/Unit_testing . By unit testing
your classes, you can isolate any errors much more quickly. Here it
would help you get the Java classes themselves working properly before
you tried to use them with Jess.
I see some other problems here, too. For example, if a
PropertyChangeEvent were ever received by Jess from this code, Jess
would actually throw another exception, reporting that there's no such
property named "cur_eventtype" in the CurrentEvent class; there's only
a read-only property named "reading", defined by the "getReading()"
method. There's unsynchronized access to your member variables across
multiple threads.
On Sep 8, 2008, at 6:11 AM, John Chrysakis wrote:
Hello again to all Jess Users,
I am trying to use propertychange listeners in a simple jess
application.
But I am getting: "Jess reported an error in routine
DefinstanceList.updateMultipleSlots"
The application examines the Type of an event and prints different
message
So the EventRules.clp has the following rules:
(import pack.*)
(deftemplate CurrentEvent(declare (from-class CurrentEvent )))
(defrule check-event-type
(CurrentEvent {reading == "TypeX" } ) => (printout t "Event TypeX"
crlf))
(defrule check-event-type
(CurrentEvent {reading == "TypeY" } ) => (printout t "Event TypeY"
crlf))
(defrule check-event-type
(CurrentEvent {reading == "TypeZ" } ) => (printout t "Event TypeX"
crlf))
I hava a BeanSupport Class like the one of page 230 /Jess In Action
Book.
I hava a BeanSimulator which fills some values the class
CurrentEvent (My
Bean Class) and the TestJessBean which includes the main and the
required
function calls to Java API.
Any ideas please, what I'm doing wrong?
Thanks in advance,
//////////////////////////////////////////////////////////////////////////////////////////////////
package pack;
public class BeanSimulator implements Runnable {
private String theEventType;
public BeanSimulator(){
new Thread (this).start();
}
public String getEventType(){
return theEventType;
}
public void run(){
theEventType = "TypeY";
while (true){
try {
for (int i=0; i<3; i++){
theEventType = "TypeX";
Thread.sleep(1000);
theEventType = "TypeY";
Thread.sleep(1000);
theEventType = "TypeZ";
Thread.sleep(1000);
}
} catch (InterruptedException e) {
e.printStackTrace();
return;
}
}
}
}
/////////////////////////////////////////////////////////////////////////////////////////
package pack;
public class CurrentEvent extends BeanSupport implements Runnable{
private String event_type;
private String event_type_old;
private String event_sender;
private BeanSimulator bs;
public CurrentEvent(String type, String sender){
event_type = type;
event_sender = sender;
}
public CurrentEvent(){
}
public String getReading(){
return bs.getEventType();
//return "TypeY";
}
public void run() {
while (true) {
String cur_eventtype = getReading();
m_pcs
.firePropertyChange("cur_eventtype",event_type_old,cur_eventtype);
event_type_old = cur_eventtype;
try { Thread.sleep(1000); }
catch (InterruptedException ie) { return; }
}
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////
package pack;
import java.io.IOException;
import jess.*;
public class TestJessBean {
public static void main (String[] args) throws
InterruptedException, IOException {
JessHandler jesshand; // Makes run-until-halt and
handls
rete Objects (Engine)
CurrentEvent cev = new CurrentEvent();
try {
jesshand = new JessHandler();
jesshand.batch("EventRules.clp");
BeanSimulator bs = new BeanSimulator();
//jesshand.add(cev);
jesshand.defClass("CurrentEvent","CurrentEvent",null);
jesshand.defInstance("CurrentEvent",cev, true);
} catch (JessException e) {
e.printStackTrace();
}
}
}
-----------------------------------------------------
John Chrysakis
R&D Engineer,
Institute of Computer Science (ICS),
Foundation for Research and Technology-Hellas (FORTH)
Heraklion, Crete, Greece.
-----------------------------------------------------
--------------------------------------------------------------------
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
Informatics & Decision Sciences, Sandia National Laboratories
PO Box 969, MS 9012, Livermore, CA 94550
http://www.jessrules.com
--------------------------------------------------------------------
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]
--------------------------------------------------------------------