0
我想在按下JButton時在我的RCP項目中發佈一個事件。爲此我嘗試使用IEventBroker。Java: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註釋是在哪裏定義的。
那麼想必注入工作不填充'eventBroker'。你使用調試器來驗證? – 2014-10-29 17:32:56
你是如何創建這個課程的? Eclipse僅對從應用程序模型創建的對象進行注入。 – 2014-10-29 17:35:28
如何驗證注射不起作用?請原諒我缺乏知識。 :) 此類用於繪製甘特圖: 公共類GanttFrame延伸ApplicationFrame實現MouseWheelListener的,的ChangeListener,AxisChangeListener,ActionListener的{ 。然後通過AWT框架添加到視圖組合中 Composite composite = new Composite(scrolledComposite,SWT.EMBEDDED | SWT.NO_BACKGROUND); frame = SWT_AWT.new_Frame(composite); – 2c00L 2014-10-29 17:40:25