在侦听器中调用函数会向我显示IllegalStateException

时间:2015-04-24 20:36:29

标签: java exception listener call skype

我正在尝试将Java Skype API集成到我的程序中。我在API文档中找到了一个示例代码,该代码使用Java侦听器来获取当前的调用状态。我在我的程序中实现了代码,每次Skype调用状态发生变化时我都需要调用一个函数(addLog函数),但是当我调用这样的函数时,控制台会向我显示“Exception in thread "AsyncSkypeMessageSender-18" java.lang.IllegalStateException”。

当我在侦听器中使用命令System.out.ln时,它正在运行它应该如何,没有任何错误,但每次我在侦听器中调用一个函数时,它都会给我一个错误。

你们知道解决我的问题吗,我认为这可能是与线程相关的问题,但我不熟悉Java编程。

代码是:

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...");
                    }
                }

            });
        }
    });

}

完整的堆栈跟踪如下:

  

线程“AsyncSkypeMessageSender-18”中的异常   java.lang.IllegalStateException:不在FX应用程序线程上;   currentThread = AsyncSkypeMessageSender-18 at   com.sun.javafx.tk.Toolkit.checkFxUserThread(未知来源)at at   com.sun.javafx.tk.quantum.QuantumToolkit.checkFxUserThread(未知   来源)在javafx.scene.Scene.addToDirtyList(未知来源)at   javafx.scene.Node.addToSceneDirtyList(未知来源)at   javafx.scene.Node.impl_markDirty(未知来源)at   javafx.scene.shape.Shape.impl_markDirty(未知来源)at   javafx.scene.text.Text.geomChanged(未知来源)at   javafx.scene.text.Text.impl_geomChanged(未知来源)at   javafx.scene.text.Text.needsTextLayout(未知来源)at   javafx.scene.text.Text.needsFullTextLayout(未知来源)at   javafx.scene.text.Text.access $ 200(未知来源)at   javafx.scene.text.Text $ 2.invalidated(未知来源)at   javafx.beans.property.StringPropertyBase.markInvalid(未知来源)     在javafx.beans.property.StringPropertyBase.set(未知来源)at   javafx.beans.property.StringPropertyBase.set(未知来源)at   javafx.scene.text.Text.setText(未知来源)at   com.sun.javafx.scene.control.skin.TextAreaSkin.lambda $新的$ 231(未知   来源)at   com.sun.javafx.scene.control.skin.TextAreaSkin $$ LAMBDA $ 172 / 1330104206.invalidated(未知   来源)at   com.sun.javafx.binding.ExpressionHelper $ Generic.fireValueChangedEvent(未知   来源)at   com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(未知   来源)at   javafx.scene.control.TextInputControl $ TextProperty.fireValueChangedEvent(未知   来源)at   javafx.scene.control.TextInputControl $ TextProperty.markInvalid(未知   来源)at   javafx.scene.control.TextInputControl $ TextProperty.invalidate(未知   来源)at   javafx.scene.control.TextInputControl $ TextProperty.access $ 1300(未知   来源)at   javafx.scene.control.TextInputControl.lambda $ new $ 163(未知来源)     在   javafx.scene.control.TextInputControl $$ LAMBDA $ 77 / 323047656.invalidated(未知   来源)at   com.sun.javafx.binding.ExpressionHelper $ SingleInvalidation.fireValueChangedEvent(未知   来源)at   com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(未知   来源)at   javafx.scene.control.TextArea $ TextAreaContent.insert(未知来源)     在javafx.scene.control.TextInputControl.replaceText(未知来源)     在javafx.scene.control.TextInputControl.insertText(未知来源)     在javafx.scene.control.TextInputControl.appendText(未知来源)     在SkypeVoicer.addLog(SkypeVoicer.java:186)at   SkypeVoicer $ 2 $ 1.statusChanged(SkypeVoicer.java:157)at at   com.skype.Call.fireStatusChanged(Call.java:339)at   com.skype.ConnectorListenerImpl.messageReceived(ConnectorListenerImpl.java:61)     在   com.skype.connector.Connector.fireMessageEvent(Connector.java:1160)     在com.skype.connector.Connector.access $ 500(Connector.java:37)at   com.skype.connector.Connector $ 13.run(Connector.java:1139)at   java.util.concurrent.ThreadPoolExecutor.runWorker(未知来源)at   java.util.concurrent.ThreadPoolExecutor $ Worker.run(未知来源)at   java.lang.Thread.run(未知来源)

0 个答案:

没有答案