java - Calling a function inside a listener is showing me a IllegalStateException -
i'm trying integrate java skype api in program. found example code in api documentation using java listeners current call status. implemented code in program , need call function (addlog function) every time skype call status changes, when call such function, console showing me "exception in thread "asyncskypemessagesender-18" java.lang.illegalstateexception
".
when use command system.out.ln
inside listener, working how supposed to, without errors, every time call function inside listener, gives me error.
do guys know solve problem, thought may thread related issue, i'm not familiar java programming.
the code is:
public void addlog(string log){ date date = new date(); simpledateformat datetime = new simpledateformat("dd/mm hh:mm:ss"); string datetimestring = datetime.format(date); logarea.appendtext(datetimestring + " > " + log); } public void makecall() throws skypeexception { skype.call("echo123"); skype.setdaemon(false); //skype.setdebug(true); system.out.println(" --------------------------------"); system.out.println(" ------ fazendo ligação... ------"); system.out.println(" --------------------------------"); skypevoicer skypevoicer = new skypevoicer(); skypevoicer.addlog("iniciou ligação\n"); skype.addcalllistener(new calladapter() { public void callmaked(call makedcall){ makedcall.addcallstatuschangedlistener(new callstatuschangedlistener(){ @override public void statuschanged(status status) throws skypeexception { if(status == status.finished){ system.out.println("finalizou, chamada de " + makedcall.getduration() + " segundos..."); skypevoicer.addlog("\nfinalizou em "+makedcall.getduration()+" segundos"); makedcall.removecallstatuschangedlistener(this); } else if(status == status.cancelled){ system.out.println("cancelado"); } else if(status == status.routing){ system.out.println("redirecionando..."); } else if(status == status.ringing){ system.out.println("tocando..."); } else if(status == status.inprogress){ system.out.println("em progresso..."); skypevoicer.addlog("em progresso..."); } } }); } }); }
the full stack trace 1 bellow:
exception in thread "asyncskypemessagesender-18" java.lang.illegalstateexception: not on fx application thread; currentthread = asyncskypemessagesender-18 @ com.sun.javafx.tk.toolkit.checkfxuserthread(unknown source) @ com.sun.javafx.tk.quantum.quantumtoolkit.checkfxuserthread(unknown source) @ javafx.scene.scene.addtodirtylist(unknown source) @ javafx.scene.node.addtoscenedirtylist(unknown source) @ javafx.scene.node.impl_markdirty(unknown source) @ javafx.scene.shape.shape.impl_markdirty(unknown source) @ javafx.scene.text.text.geomchanged(unknown source) @ javafx.scene.text.text.impl_geomchanged(unknown source) @ javafx.scene.text.text.needstextlayout(unknown source) @ javafx.scene.text.text.needsfulltextlayout(unknown source) @ javafx.scene.text.text.access$200(unknown source) @ javafx.scene.text.text$2.invalidated(unknown source) @ javafx.beans.property.stringpropertybase.markinvalid(unknown source) @ javafx.beans.property.stringpropertybase.set(unknown source) @ javafx.beans.property.stringpropertybase.set(unknown source) @ javafx.scene.text.text.settext(unknown source) @ com.sun.javafx.scene.control.skin.textareaskin.lambda$new$231(unknown source) @ com.sun.javafx.scene.control.skin.textareaskin$$lambda$172/1330104206.invalidated(unknown source) @ com.sun.javafx.binding.expressionhelper$generic.firevaluechangedevent(unknown source) @ com.sun.javafx.binding.expressionhelper.firevaluechangedevent(unknown source) @ javafx.scene.control.textinputcontrol$textproperty.firevaluechangedevent(unknown source) @ javafx.scene.control.textinputcontrol$textproperty.markinvalid(unknown source) @ javafx.scene.control.textinputcontrol$textproperty.invalidate(unknown source) @ javafx.scene.control.textinputcontrol$textproperty.access$1300(unknown source) @ javafx.scene.control.textinputcontrol.lambda$new$163(unknown source) @ javafx.scene.control.textinputcontrol$$lambda$77/323047656.invalidated(unknown source) @ com.sun.javafx.binding.expressionhelper$singleinvalidation.firevaluechangedevent(unknown source) @ com.sun.javafx.binding.expressionhelper.firevaluechangedevent(unknown source) @ javafx.scene.control.textarea$textareacontent.insert(unknown source) @ javafx.scene.control.textinputcontrol.replacetext(unknown source) @ javafx.scene.control.textinputcontrol.inserttext(unknown source) @ javafx.scene.control.textinputcontrol.appendtext(unknown source) @ skypevoicer.addlog(skypevoicer.java:186) @ skypevoicer$2$1.statuschanged(skypevoicer.java:157) @ com.skype.call.firestatuschanged(call.java:339) @ com.skype.connectorlistenerimpl.messagereceived(connectorlistenerimpl.java:61) @ com.skype.connector.connector.firemessageevent(connector.java:1160) @ com.skype.connector.connector.access$500(connector.java:37) @ com.skype.connector.connector$13.run(connector.java:1139) @ java.util.concurrent.threadpoolexecutor.runworker(unknown source) @ java.util.concurrent.threadpoolexecutor$worker.run(unknown source) @ java.lang.thread.run(unknown source)
Comments
Post a Comment