Java:IEventBroker null点异常

时间:2014-10-29 17:26:50

标签: java eclipse events eclipse-rcp e4

当我按下JButton时,我想在我的RCP项目中发布一个事件。为此,我试图使用IEventBroker。

我遵循了vogella.com here的教程。

 @Inject
 private IEventBroker eventBroker; 

 @Override
    public void actionPerformed(ActionEvent arg0) {

        // THE UPDATE BUTTON
        if (arg0.getSource()== update) {

            System.out.println("Button Pressed");

            eventBroker.post("test", "New data"); // generates a null point exception
            .....
            .....

不幸的是,这会产生一个零点异常。

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at chipcoach.tableviewerDMA.GanttFrame.actionPerformed(GanttFrame.java:522)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$400(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

在本教程的后半部分,它也没有说明@EventTopic和@UIEventTopic注释的定义位置。

1 个答案:

答案 0 :(得分:0)

基督徒在Event Broker上的绝对辉煌tutorial解决了我在如何在我的RCP项目中使用Event Broker的问题。

需要添加以下依赖项:

org.eclipse.e4.core.services 
org.eclipse.osgi.services