Hi,I'm trying to write a program that asks a user his telephone number in
GUI, then searches a database for that phone # using defquery, and outputs
some results. But when I run it I get an error as below.
Jess reported an error in routine QueryResult.get
while executing (call ?result getInt ca)
while executing (printout t ?text crlf (call ?result getInt ca))
while executing deffunction running-query
while executing (running-query ?text)
while executing deffunction read-input
while executing (read-input <Java-Object:java.awt.event.ActionEvent>).
Message: The cursor is before the first row; you must call next() before
accessing query result .
Since I called next() before accessing query result, I thought the error
might be caused by calling the defquery within a deffunction. Following is
the program I wrote. I'd appreciate any help.
;(watch all)
(import javax.swing.*)
(import javax.swing.JFrame)
(import java.awt.event.ActionListener)
(import java.awt.BorderLayout)
(import java.awt.Color)
(import javax.swing.*)
(import java.awt.*)
(import java.awt.event.*)
(defglobal ?*f* = (new JFrame "Testing"))
(defglobal ?*c* = (?*f* getContentPane))
(defglobal ?*apanel* = (new JPanel))
(defglobal ?*afield* = (new JTextField 40))
(defglobal ?*afield-ok* =(new JButton OK))
(?*apanel* add ?*afield*)
(?*apanel* add ?*afield-ok*)
((?*f* getContentPane) add ?*apanel*
(get-member BorderLayout CENTER))
(?*f* validate)
(?*f* repaint)
(?*c* add (new JLabel "What is the phone number? ") (BorderLayout.NORTH))
(deftemplate conditions
(slot telnumb)
(slot adr)
(slot esc)
(slot sta)
(slot car))
(deffacts testdata
(conditions (telnumb 4978548) (adr 8) (esc 0) (sta 4) (car 4))
(conditions (telnumb 8754655) (adr 5) (esc 0) (sta 1) (car 6))
(conditions (telnumb 9856211) (adr 1) (esc 0) (sta 7) (car 2))
(conditions (telnumb 5284877) (adr 8) (esc 1) (sta 2) (car 5))
(conditions (telnumb 9845652) (adr 8) (esc 0) (sta 1) (car 1))
)
(defquery search-by-telnumb
"Finds locations with given telephone number"
(declare (variables ?tn))
(conditions (telnumb ?tn) (adr ?ad) (esc ?es) (sta ?st) (car ?ca)))
(deffunction running-query (?text)
(bind ?result (run-query* search-by-telnumb ?text))
(?result next)
(printout t ?text crlf (?result getInt ca))
)
(deffunction read-input (?EVENT)
(bind ?text (sym-cat (?*afield* getText)))
(running-query ?text)
)
(bind ?handler (new jess.awt.ActionListener read-input (engine)))
(?*afield* addActionListener ?handler)
(?*afield-ok* addActionListener ?handler)
(?*f* setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE))
(?*f* pack)
(?*f* setSize 520 150)
(?*f* setVisible TRUE)
Thank you,
Seyed