[英]Error when passing values to other view in eclipse e4
I am using IEventBroker to send the events to other view synchronously 我正在使用IEventBroker将事件同步发送到其他视图
@Inject
private IEventBroker eventBroker;
The sender part has the following code: 发送方部分具有以下代码:
Map<String,List<TreeMap<Timestamp, Long>>> StatisticValue = new HashMap<String,List<TreeMap<Timestamp, Long>>>();
//some code to add values in statisticValue
eventBroker.send("value", StatisticValue);
The receiver side has the following code snippet. 接收器端具有以下代码段。
@Inject
@Optional
public void getEvent(@UIEventTopic("value")HashMap<String,List<TreeMap<Timestamp, Long>>> entriesForTs)
{
System.out.println("size"+entriesForTs.size());
}
I am getting the following error in the receiving end: 我在接收端收到以下错误:
Exception while dispatching event org.osgi.service.event.Event [topic=value] to handler org.eclipse.e4.ui.internal.di.UIEventObjectSupplier$UIEventHandler@6d79dea2
!STACK 0
org.eclipse.e4.core.di.InjectionException: java.lang.NullPointerException
at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:63)
at org.eclipse.e4.ui.internal.di.UIEventObjectSupplier$UIEventHandler$1.run(UIEventObjectSupplier.java:49)
at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java:180)
at org.eclipse.swt.widgets.Display.syncExec(Display.java:4688)
at org.eclipse.e4.ui.internal.workbench.swt.E4Application$1.syncExec(E4Application.java:205)
at org.eclipse.e4.ui.internal.di.UIEventObjectSupplier$UIEventHandler.handleEvent(UIEventObjectSupplier.java:47)
at org.eclipse.equinox.internal.event.EventHandlerWrapper.handleEvent(EventHandlerWrapper.java:197)
at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:197)
at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:1)
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)
at org.eclipse.equinox.internal.event.EventAdminImpl.dispatchEvent(EventAdminImpl.java:135)
at org.eclipse.equinox.internal.event.EventAdminImpl.sendEvent(EventAdminImpl.java:78)
at org.eclipse.equinox.internal.event.EventComponent.sendEvent(EventComponent.java:39)
at org.eclipse.e4.ui.services.internal.events.EventBroker.send(EventBroker.java:80)
at com.xyz.abc.project.parts.StatisticsPart.processFiles(StatisticsPart.java:270)
at com.xyz.abc.project.parts.StatisticsPart$5.selectionChanged(StatisticsPart.java:205)
at org.eclipse.jface.viewers.Viewer$2.run(Viewer.java:164)
at org.eclipse.jface.util.SafeRunnable$1.run(SafeRunnable.java:128)
at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:175)
at org.eclipse.jface.viewers.Viewer.fireSelectionChanged(Viewer.java:162)
at org.eclipse.jface.viewers.StructuredViewer.updateSelection(StructuredViewer.java:2188)
at org.eclipse.jface.viewers.StructuredViewer.handleSelect(StructuredViewer.java:1211)
at org.eclipse.jface.viewers.StructuredViewer$4.widgetSelected(StructuredViewer.java:1241)
at org.eclipse.jface.util.OpenStrategy.fireSelectionEvent(OpenStrategy.java:239)
at org.eclipse.jface.util.OpenStrategy.access$4(OpenStrategy.java:233)
at org.eclipse.jface.util.OpenStrategy$1.handleEvent(OpenStrategy.java:403)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1057)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4170)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3759)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1113)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:997)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:138)
at org.eclipse.e4.ui.internal.workbench.swt.E4Application.start(E4Application.java:162)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:354)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:181)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:636)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:591)
at org.eclipse.equinox.launcher.Main.run(Main.java:1450)
at org.eclipse.equinox.launcher.Main.main(Main.java:1426)
Caused by: java.lang.NullPointerException
at com.xyz.abc.project.parts.showGraph.getEvent(showGraph.java:109)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:56)
... 48 more
I am confused why am I getting this error. 我很困惑为什么我会收到此错误。 I have checked the size(size = 2) of the StatisticValue in the sender side.
我已经在发送方检查了StatisticValue的大小(大小= 2)。 But it is showing some nullpointer exception.
但是它显示了一些nullpointer异常。 Can anyone please help me?
谁能帮帮我吗?
The exception is reporting a NullPointerException
in your getEvent
method because the entriesForTs
is null. 异常是在
getEvent
方法中报告NullPointerException
,因为entriesForTs
为null。
The @UIEventTopic
handling code seems to call the event handler once with a null value the first time it is used (and then calls it again with the correct value). @UIEventTopic
处理代码似乎在第一次使用事件处理程序时使用空值调用一次(然后使用正确的值再次调用它)。 So just check for null in your getEvent
. 因此,只需在
getEvent
检查null。
Update: 更新:
You could try using org.osgi.service.event.Event
as the type of the getEvent
argument in case there is some problem with resolving the argument type: 您可以尝试使用
org.osgi.service.event.Event
作为getEvent
参数的类型,以防解析参数类型时遇到一些问题:
public void getEvent(@UIEventTopic("value") Event event)
{
data = event.getProperty(IEventBroker.DATA);
You could also try IEventBroker.subscribe
if the @UIEventTopic
refuses to work. 如果
@UIEventTopic
拒绝工作,您也可以尝试IEventBroker.subscribe
。
Update 2: 更新2:
The event broker send
(and post
) methods treat Map
specially and assumes it is a map containing the values you want to send. 事件代理的
send
(和post
)方法特别对待Map
并假定它是一个包含您要发送的值的map。 So it will be looking in the Map for an IEventBroker.DATA
key. 因此它将在Map中寻找
IEventBroker.DATA
键。 It would be best to wrap your map in a container class. 最好将地图包装在容器类中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.