运行两个独立的线程时获取java.lang.reflect.InvocationTargetException

时间:2014-04-07 01:39:17

标签: java multithreading javafx javafx-2

我有两个班级ResultsReaderResultsReadertwo。这两个类都扩展了Task类,我使用了两个不同的线程,如下所示:

在ResultsReader类中:

public void act_StartProcessing() 
    { new Thread(this).start(); }

    public void act_StopProcessing() 
    { this.cancel();}

在ResultReadertwo课程中

public void act_StartProcessing2() 
    { new Thread(this).start(); }

    public void act_StopProcessing2() 
    { this.cancel();}

我得到的例外情况如下:

java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1456)
    at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:69)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:217)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:170)
    at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:38)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:37)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
    at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:53)
    at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:28)
    at javafx.event.Event.fireEvent(Event.java:171)
    at javafx.scene.Node.fireEvent(Node.java:6867)
    at javafx.scene.control.Button.fire(Button.java:179)
    at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:193)
    at com.sun.javafx.scene.control.skin.SkinBase$4.handle(SkinBase.java:336)
    at com.sun.javafx.scene.control.skin.SkinBase$4.handle(SkinBase.java:329)
    at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:64)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:217)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:170)
    at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:38)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:37)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
    at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:53)
    at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:33)
    at javafx.event.Event.fireEvent(Event.java:171)
    at javafx.scene.Scene$MouseHandler.process(Scene.java:3369)
    at javafx.scene.Scene$MouseHandler.process(Scene.java:3209)
    at javafx.scene.Scene$MouseHandler.access$1900(Scene.java:3164)
    at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1582)
    at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2267)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:250)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:173)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:292)
    at com.sun.glass.ui.View.handleMouseEvent(View.java:530)
    at com.sun.glass.ui.View.notifyMouse(View.java:924)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:17)
    at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:67)
    at java.lang.Thread.run(Thread.java:744)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:75)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:279)
    at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1451)
    ... 44 more
Caused by: java.lang.UnsupportedOperationException: Not supported yet.
    at ebmextractor.ExtractorMonitor.set_QRS2(ExtractorMonitor.java:119)
    at ebmextractor.EBMExtractorFXMLController.act_Start(EBMExtractorFXMLController.java:428)
    ... 55 more

这是EBMExtractorFXMLController类中的一段代码,我收到错误:

RunningQRState = false;

             ExtractorMonitor QRM = new ExtractorMonitor();

             QRM.set_but_Start(but_Start);
             QRM.set_QRS(QueuyeReaderExecutorService);
             QRM.set_QRS2(QueuyeReaderExecutorService2);// Getting error here
             QRM.act_StartProcessing();  
             QRM.act_StartProcessing2(); 

Here是我的ExtractorMonitor课程,我已定义act_StartProcessing(); and act_StartProcessing2();

请让我知道我做错了什么?感谢

1 个答案:

答案 0 :(得分:0)

问题的根源似乎是:

Caused by: java.lang.UnsupportedOperationException: Not supported yet.
at ebmextractor.ExtractorMonitor.set_QRS2(ExtractorMonitor.java:119)

这与多线程无关。

最可能的原因是此方法会抛出UnsupportedOperationException。你确定你/你的IDE没有为你抛出这个异常吗?

您发布的源代码链接似乎并未指向您在问题中引用的类的版本。没有行ExtractorMonitor.java:119