Hi,
I am creating a set of Tcl commands over a java application. Without a
seperate thread for Tcl interpreter, the commands I created worked fine in
java. However, taking the advice from Mr. Wu, I am trying to create a
seperate thread for Tcl interpreter but I couldn't make it work.
In my small example, except for a main class to create a graphic
interface, I have two classes, called "DrawCmmd" which implements
tcl.lang.Command and "DrawEXtension" which extends tcl.lang.Extension, to
create and register tcl commmans "draw line" or "draw polygon". I also
have another two classes, TclInterpreterThread and MyTclEvent which are
similar to the examples in the tutorial. When I am trying to run it I got
the following exception and the "draw line/polygon" doesn't work. Could
anybody
please help me fix this problem? I'll really appreciate it.
Thanks
The run time exception are:
java.lang.NullPointerException
at TestThread.drawline(TestThread.java:93)
at DrawCmmd.cmdProc(TestThread.java:232)
at tcl.lang.Interp.callCommand(Interp.java:953)
at tcl.lang.Interp.eval(Native Method)
at tcl.lang.Interp.eval(Interp.java:783)
at MyTclEvent.hello(TestThread.java:197)
at MyTclEvent.processEvent(TestThread.java:184)
at tcl.lang.Notifier.serviceEvent(Compiled Code)
at tcl.lang.Notifier.doOneEvent(Native Method)
at tcl.lang.Notifier.doOneEvent(Compiled Code)
at TclInterpreterThread.run(Compiled Code)
tcl.lang.TclRuntimeError: Error in command implementation
at tcl.lang.Interp.eval(Native Method)
at tcl.lang.Interp.eval(Interp.java:783)
at MyTclEvent.hello(TestThread.java:197)
at MyTclEvent.processEvent(TestThread.java:184)
at tcl.lang.Notifier.serviceEvent(Compiled Code)
at tcl.lang.Notifier.doOneEvent(Native Method)
at tcl.lang.Notifier.doOneEvent(Compiled Code)
at TclInterpreterThread.run(Compiled Code)
Here are the two classes which create the thread:
class TclInterpreterThread extends Thread {
public Interp mInterp = null;
TestThread mFrame;
public TclInterpreterThread (TestThread frame ) {
mFrame = frame;
}
public void run () {
mInterp = new Interp();
DrawExtension de = new DrawExtension();
de.init(mInterp,mFrame);
MyTclEvent event = new MyTclEvent(mInterp);
Notifier notifier = mInterp.getNotifier();
notifier.queueEvent(event,TCL.QUEUE_TAIL);
while (true) {
notifier.doOneEvent(TCL.ALL_EVENTS);
}
}
}
/***********************************************************/
class MyTclEvent extends TclEvent {
private Interp mInterp = null;
public MyTclEvent (Interp interp) {
}
public int processEvent (int flags) {
try {
hello(mIterp);
} catch (TclException e) {
e.printStackTrace();
}
return 1;
}
public void hello (Interp interp)
throws TclException
{
interp.eval("draw line");
interp.eval("puts {Hello, World}");
}
}
Thanks again
Zhumei
----------------------------------------------------------------
The TclJava mailing list is sponsored by Scriptics Corporation.
To subscribe: send mail to [EMAIL PROTECTED]
with the word SUBSCRIBE as the subject.
To unsubscribe: send mail to [EMAIL PROTECTED]
with the word UNSUBSCRIBE as the subject.
To send to the list, send email to '[EMAIL PROTECTED]'.
An archive is available at http://www.mail-archive.com/[email protected]