JavaFX call to SWT update exception - java

I have a keyboard emulation class which has a method to type to the Eclipse editor automatically based on voice recognition input. This works correctly.
I also have tables made in JavaFX, in which a user clicks an element and it too is emulated to the screen using the same method.
However, I am getting "Exception in thread "JavaFX Application Thread" java.lang.NullPointerException" exceptions. This does not happen from the voice recognition part, only when the JavaFX thread calls the method to update the Eclipse editor.
Keyboard Emulation method which prints data to the eclipse text editor
private void doType(int[] keyCodes, int offset, int length) {
if (length == 0) {
return;
}
//Since we are in a loop, we must only emulate the mouse press on the eclipse
//text editors last known location to avoid every letter getting mixed up
correctCaretPosition++;
Display.getDefault().syncExec(new Runnable() {
public void run() {
System.out.println("fwefwefwef\n\n\n\n\n\n" + myEditor.PROP_DIRTY);
Control control = myEditor.getAdapter(Control.class);
//Only when the click to bring eclipse into scope has not happened
if (control instanceof StyledText && correctCaretPosition <= 1) {
StyledText text = (StyledText)control;
// Position of caret relative to top left of the control
Point relPos = text.getLocationAtOffset(text.getCaretOffset());
// Position relative to display
Point absPos = text.toDisplay(relPos);
System.out.println(absPos.x + " " +absPos.y);
robot.mouseMove(absPos.x, absPos.y);
robot.mousePress(BUTTON1_MASK);
robot.mouseRelease(BUTTON1_MASK);
}
robot.keyPress(keyCodes[offset]);
doType(keyCodes, offset + 1, length - 1);
robot.keyRelease(keyCodes[offset]);
}
});
}
JavaFX call to Keyboard Emulation
Platform.runLater(new Runnable() {
#Override
public void run()
{
robot.type(data);
}
});
The error comes from this line
Control control = myEditor.getAdapter(Control.class);
Robot in this context is the Keybooard Emulation object.
Am I getting the concurrency between the two completely wrong?
UPDATE:
The root of the error is
Control control = myEditor.getAdapter(Control.class);
I passed in the control from the beginning of the application, no error, however, nothing happens as I believe the control does not satify
if (control instanceof StyledText && correctCaretPosition <= 1) {
Updated Stack-trace
Exception in thread "JavaFX Application Thread"
!ENTRY org.eclipse.ui 4 0 2016-02-24 16:36:49.413
!MESSAGE Unhandled event loop exception
org.eclipse.swt.SWTException: Failed to execute runnable (java.lang.NullPointerException)
at org.eclipse.swt.SWT.error(SWT.java:4491)
at org.eclipse.swt.SWT.error(SWT.java:4406)
at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java:208)
at org.eclipse.ui.internal.UISynchronizer.syncExec(UISynchronizer.java:145)
at org.eclipse.swt.widgets.Display.syncExec(Display.java:4761)
at voice.recognition.Keyboard_Emulation.doType(Keyboard_Emulation.java:204)
at voice.recognition.Keyboard_Emulation.doType(Keyboard_Emulation.java:191)
at voice.recognition.Keyboard_Emulation.type(Keyboard_Emulation.java:174)
at voice.recognition.Keyboard_Emulation.type(Keyboard_Emulation.java:69)
at table.symbol.SymbolTableController$1$1.run(SymbolTableController.java:92)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException
at voice.recognition.Keyboard_Emulation$1.run(Keyboard_Emulation.java:208)
at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135)
at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4155)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3772)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$4.run(PartRenderingEngine.java:1127)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1018)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:156)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:654)
!STACK 0
org.eclipse.swt.SWTException: Failed to execute runnable (java.lang.NullPointerException)
at org.eclipse.swt.SWT.error(SWT.java:4491)
at org.eclipse.swt.SWT.error(SWT.java:4406)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:138)
at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4155)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3772)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$4.run(PartRenderingEngine.java:1127)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1018)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:156)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:654)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:598)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:139)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:380)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:235)
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:669)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:608)
at org.eclipse.equinox.launcher.Main.run(Main.java:1515)
at org.eclipse.equinox.launcher.Main.main(Main.java:1488)
Caused by: java.lang.NullPointerException
at voice.recognition.Keyboard_Emulation$1.run(Keyboard_Emulation.java:208)
at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135)
... 24 more
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:598)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:139)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:380)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:235)
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:669)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:608)
at org.eclipse.equinox.launcher.Main.run(Main.java:1515)
at org.eclipse.equinox.launcher.Main.main(Main.java:1488)

Related

Eclipse NullPointerException when dragging tab to a new location with custom perspectives

I made an IPartListener so when I change between different file types I can change perspective automatically. But when I drag an editor tab to a new location, it iterates over the other tabs it crossed. Now I think because of this, the editors getting activated and eclipse wants to change perspectives too fast. And I get a new tab added named: Drag Placerholder which is an ErrorViewPart.
My code:
PlatformUI.getWorkbench().getDisplay().asyncExec(() -> {
IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
workbenchWindow.getPartService().addPartListener(new IPartListener() {
#Override
public void partActivated(IWorkbenchPart part) {
if (part instanceof MyEditor && MyEditor.isAutomaticPerspectiveChangeEnabled()) {
MyEditor editor = (MyEditor) part;
try {
editor.changePerspective();
} catch (WorkbenchException e) {
ErrorHandler.handleUnexpectedError(e);
}
}
}
}
}
I attached some pics, if I drag file1.abc after file3.xyz and the files between would use other perspective, I end up with a 4th tab and a NullPointerException
I'm not sure why Eclipse is activating the tabs between the drag points, can I somehow block that?
Stacktrace:
Unhandled event loop exception
java.lang.NullPointerException
at org.eclipse.e4.ui.workbench.addons.dndaddon.DragAgent.dragFinished(DragAgent.java:171)
at org.eclipse.e4.ui.workbench.addons.dndaddon.PartDragAgent.dragFinished(PartDragAgent.java:93)
at org.eclipse.e4.ui.workbench.addons.dndaddon.DnDManager.finishDrag(DnDManager.java:285)
at org.eclipse.e4.ui.workbench.addons.dndaddon.DnDManager.startDrag(DnDManager.java:252)
at org.eclipse.e4.ui.workbench.addons.dndaddon.DnDManager$1.dragDetected(DnDManager.java:89)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:128)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4418)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1079)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4236)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3824)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$4.run(PartRenderingEngine.java:1121)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1022)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:150)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:693)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:610)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:148)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:138)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:388)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:243)
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:673)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:610)
at org.eclipse.equinox.launcher.Main.run(Main.java:1519)
at org.eclipse.equinox.launcher.Main.main(Main.java:1492)

Playing a YouTube video with JavaFX

I've watched a lot of posts about playing YouTube videos, and also watched Oracle learning tutorials. They used this code and it worked perfectly to them, but I get errors. And can't find a way to fix it.
#Override
public void start(Stage window) throws Exception
{
Media media = new Media("https://www.youtube.com/watch?v=Q0oIoR9mLwc");
MediaPlayer player = new MediaPlayer(media);
MediaView view = new MediaView(player);
player.setAutoPlay(true);
StackPane sp = new StackPane(view);
Scene sc = new Scene(sp,500,500);
window.setScene(sc);
window.show();
}
ERRORS I GET
Exception in Application start method
java.lang.reflect.InvocationTargetException
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 com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(Unknown Source)
at com.sun.javafx.application.LauncherImpl.launchApplication(Unknown Source)
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 sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(Unknown Source)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.UnsupportedOperationException: Unsupported protocol "https"
at com.sun.media.jfxmedia.locator.Locator.<init>(Unknown Source)
at javafx.scene.media.Media.<init>(Unknown Source)
at PlayVideo.Main.start(Main.java:34)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(Unknown Source)
... 1 more
Exception running application PlayVideo.Main
I also checked this link on stackoverflow but couldn't find solution. Link
Also tried it this way but video won't load.
#Override public void start(Stage stage) throws Exception {
WebView webview = new WebView();
webview.getEngine().load(
"https://www.youtube.com/watch?v=jaPUbzfJx2A"
);
webview.setPrefSize(640, 390);
stage.setScene(new Scene(webview));
stage.show();
}
}

Dispose of a non disposed CTabFolder raises SWTException: Widget is disposed

In my Eclipse 4 RCP App I want to dispose some CTabFolders. I check if they are already disposed and if not I dispose them. But it still raises an SWTException: Widget is disposed.
I checked if every CTabFolder in stageDataTabFolders is unique.
Here is the code fragment:
for (Tuple<CTabItem, CTabFolder> stageDataTabFolder : stageDataTabFolders) {
if (!stageDataTabFolder.getSecond().isDisposed()) {
stageDataTabFolder.getSecond().dispose();
}
}
And the Exception:
!ENTRY org.eclipse.equinox.event 4 0 2016-04-11 11:28:20.317
!MESSAGE Exception while dispatching event org.osgi.service.event.Event [topic=org/eclipse/e4/ui/LifeCycle/activate] to handler org.eclipse.e4.ui.services.internal.events.UIEventHandler#da28d03
!STACK 0
org.eclipse.swt.SWTException: Widget is disposed
at org.eclipse.swt.SWT.error(SWT.java:4441)
at org.eclipse.swt.SWT.error(SWT.java:4356)
at org.eclipse.swt.SWT.error(SWT.java:4327)
at org.eclipse.swt.widgets.Widget.error(Widget.java:476)
at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:348)
at org.eclipse.swt.widgets.Widget.getData(Widget.java:562)
at org.eclipse.e4.ui.css.swt.engine.AbstractCSSSWTEngineImpl.isStylable(AbstractCSSSWTEngineImpl.java:118)
at org.eclipse.e4.ui.css.swt.engine.AbstractCSSSWTEngineImpl.getElement(AbstractCSSSWTEngineImpl.java:97)
at org.eclipse.e4.ui.css.core.dom.ArrayNodeList.item(ArrayNodeList.java:38)
at org.eclipse.e4.ui.css.core.impl.engine.AbstractCSSEngine.applyStyles(AbstractCSSEngine.java:430)
at org.eclipse.e4.ui.css.core.impl.engine.AbstractCSSEngine.applyStyles(AbstractCSSEngine.java:354)
at org.eclipse.e4.ui.css.core.impl.engine.AbstractCSSEngine.applyStyles(AbstractCSSEngine.java:430)
at org.eclipse.e4.ui.css.core.impl.engine.AbstractCSSEngine.applyStyles(AbstractCSSEngine.java:354)
at org.eclipse.e4.ui.css.core.impl.engine.AbstractCSSEngine.applyStyles(AbstractCSSEngine.java:430)
at org.eclipse.e4.ui.css.core.impl.engine.AbstractCSSEngine.applyStyles(AbstractCSSEngine.java:354)
at org.eclipse.e4.ui.css.swt.internal.theme.ThemeEngine.applyStyles(ThemeEngine.java:512)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$11.setClassnameAndId(PartRenderingEngine.java:1321)
at org.eclipse.e4.ui.workbench.renderers.swt.SWTPartRenderer.setCSSInfo(SWTPartRenderer.java:111)
at org.eclipse.e4.ui.workbench.renderers.swt.SWTPartRenderer.styleElement(SWTPartRenderer.java:81)
at org.eclipse.e4.ui.workbench.renderers.swt.StackRenderer$5.handleEvent(StackRenderer.java:520)
at org.eclipse.e4.ui.services.internal.events.UIEventHandler$1.run(UIEventHandler.java:40)
at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java:187)
at org.eclipse.swt.widgets.Display.syncExec(Display.java:4734)
at org.eclipse.e4.ui.internal.workbench.swt.E4Application$1.syncExec(E4Application.java:218)
at org.eclipse.e4.ui.services.internal.events.UIEventHandler.handleEvent(UIEventHandler.java:36)
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:81)
at org.eclipse.e4.ui.workbench.UIEvents.publishEvent(UIEvents.java:372)
at org.eclipse.e4.ui.workbench.UIEvents.publishEvent(UIEvents.java:341)
at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.activate(PartServiceImpl.java:657)
at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.activate(PartServiceImpl.java:620)
at org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer.activate(AbstractPartRenderer.java:106)
at org.eclipse.e4.ui.workbench.renderers.swt.ContributedPartRenderer$1.handleEvent(ContributedPartRenderer.java:61)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4353)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1061)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1085)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1070)
at org.eclipse.swt.widgets.Shell.setActiveControl(Shell.java:1453)
at org.eclipse.swt.widgets.Shell.setActiveControl(Shell.java:1416)
at org.eclipse.swt.widgets.Control.sendFocusEvent(Control.java:2855)
at org.eclipse.swt.widgets.Widget.wmSetFocus(Widget.java:2425)
at org.eclipse.swt.widgets.Control.WM_SETFOCUS(Control.java:5236)
at org.eclipse.swt.widgets.Control.windowProc(Control.java:4680)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:5023)
at org.eclipse.swt.internal.win32.OS.DestroyWindow(Native Method)
at org.eclipse.swt.widgets.Control.destroyWidget(Control.java:779)
at org.eclipse.swt.widgets.Widget.release(Widget.java:826)
at org.eclipse.swt.widgets.Widget.dispose(Widget.java:454)
at de.uni_due.s3.jack.editor.parts.stage.StagePart.dispose(StagePart.java:416)
at de.uni_due.s3.jack.editor.menu.New.resetEditor(New.java:45)
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:55)
at org.eclipse.e4.core.internal.di.InjectorImpl.invokeUsingClass(InjectorImpl.java:247)
at org.eclipse.e4.core.internal.di.InjectorImpl.invoke(InjectorImpl.java:229)
at org.eclipse.e4.core.contexts.ContextInjectionFactory.invoke(ContextInjectionFactory.java:132)
at org.eclipse.e4.core.commands.internal.HandlerServiceHandler.execute(HandlerServiceHandler.java:149)
at org.eclipse.core.commands.Command.executeWithChecks(Command.java:499)
at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:508)
at org.eclipse.e4.core.commands.internal.HandlerServiceImpl.executeHandler(HandlerServiceImpl.java:210)
at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.executeItem(HandledContributionItem.java:825)
at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.handleWidgetSelection(HandledContributionItem.java:701)
at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.access$6(HandledContributionItem.java:685)
at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem$4.handleEvent(HandledContributionItem.java:613)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4353)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1061)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4172)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3761)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1151)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1032)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:148)
at org.eclipse.e4.ui.internal.workbench.swt.E4Application.start(E4Application.java:164)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:380)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:235)
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:648)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:603)
at org.eclipse.equinox.launcher.Main.run(Main.java:1465)
at org.eclipse.equinox.launcher.Main.main(Main.java:1438)
Edit: I created them like this:
CTabFolder stageTabFolder = new CTabFolder(parent, SWT.BORDER | SWT.FLAT);
stageTabFolder.setSimple(false);
stageTabFolder.setTabPosition(SWT.BOTTOM);
CTabFolder stageDataTabFolder = new CTabFolder(stageTabFolder, SWT.TOP);
stageDataTabFolder.setSimple(false);
stageDataTabFolders.add(new Tuple<CTabItem, CTabFolder>(stageTabItem,
stageDataTabFolder));
Edit: The whole purpose is to implement a menu Item "New" to reset the App back into a virgin state. The call goes like this:
#Execute
public void resetEditor(MApplication app, IWorkbench workbench) {
MPart configPart = partService
.findPart("de.uni_due.s3.jack.editor.parts.config");
MPart stagePart = partService
.findPart("de.uni_due.s3.jack.editor.part.stage");
resetHandler();
((StagePart)stagePart.getObject()).dispose();
partService.activate(configPart);
}
On the StagePart:
public void dispose() {
for (Tuple<CTabItem, CTabFolder> stageDataTabFolder : stageDataTabFolders) {
if (!stageDataTabFolder.getSecond().isDisposed()) {
stageDataTabFolder.getSecond().dispose();
}
}
stageDataTabFolders.clear();
stageTabFolder.dispose();
}

Issue running Junit test case for eclipse RCP application

I am facing following exception while testing my exit handler for my Eclipse 4 RCP Application.
!ENTRY org.eclipse.e4.ui.workbench 2 0 2014-06-10 14:09:22.607
!MESSAGE Could not run processor
!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.core.internal.di.InjectorImpl.invokeUsingClass(InjectorImpl.java:243)
at org.eclipse.e4.core.internal.di.InjectorImpl.invoke(InjectorImpl.java:220)
at org.eclipse.e4.core.contexts.ContextInjectionFactory.invoke(ContextInjectionFactory.java:107)
at org.eclipse.e4.ui.internal.workbench.ModelAssembler.runProcessor(ModelAssembler.java:231)
at org.eclipse.e4.ui.internal.workbench.ModelAssembler.processModel(ModelAssembler.java:88)
at org.eclipse.e4.ui.internal.workbench.ResourceHandler.loadMostRecentModel(ResourceHandler.java:220)
at org.eclipse.e4.ui.internal.workbench.swt.E4Application.loadApplicationModel(E4Application.java:395)
at org.eclipse.e4.ui.internal.workbench.swt.E4Application.createE4Workbench(E4Application.java:238)
at org.eclipse.e4.ui.internal.workbench.swt.E4Application.start(E4Application.java:144)
at org.eclipse.swtbot.eclipse.core.UITestApplication.start(UITestApplication.java:54)
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 org.eclipse.e4.tools.emf.liveeditor.ModelProcessor.process(ModelProcessor.java:55)
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)
... 23 more
My test case looks like following
#RunWith(SWTBotJunit4ClassRunner.class)
public class ExitHandlerTest {
private static SWTBot bot;
#BeforeClass
public static void beforeClass() throws Exception {
bot = new SWTBot();
}
#Test
public void testExitHandler() {
SWTBotMenu fileMenu = bot.menu("File");
Assert.assertNotNull(fileMenu);
SWTBotMenu exitMenu = fileMenu.menu("Exit");
Assert.assertNotNull(exitMenu);
exitMenu.click();
}
#AfterClass
public static void sleep() {
}
}
Code for my exist handler is
public class ExitHandler {
#Execute
public void execute(IWorkbench workbench, EPartService partService, ISaveHandler saveHandler) {
workbench.close();
}
}
Although the test run fine but I am not sure why am I getting this exception.
Looks like you have the e4 live model editor included in your test and you are hitting Eclipse bug 426373.
I don't think this is actually affecting your test so you can ignore it.

foo.setText(bar) causes NullPointerException..what am i doing wrong?

I am creating an android app and needed to change the text of some textViews in one of my layouts. This is my code.
public void hudSetup() {
Player stats = new Player(this);
stats.open();
String playerName = stats.getStringField(stats.KEY_NAME);
String playerCity = stats.getStringField(stats.KEY_CITY);
int playerHealth = stats.getIntField(stats.KEY_HEALTH);
int playerEnergy = stats.getIntField(stats.KEY_ENERGY);
int playerRank= stats.getIntField(stats.KEY_RANK);
int playerCash = stats.getIntField(stats.KEY_CASH);
stats.close();
name.setText(playerName);
city.setText(playerCity);
energy.setText(playerEnergy);
health.setText(playerHealth);
cash.setText(playerCash);
rank.setText(playerRank);
}
I have ensured all of my textViews are initialised. The code compiles, however when i run the app and the hudSetup() method runs, I get a nullPointerException.
org.eclipse.swt.SWTException: Failed to execute runnable (java.lang.NullPointerException)
at org.eclipse.swt.SWT.error(SWT.java:4282)
at org.eclipse.swt.SWT.error(SWT.java:4197)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:138)
at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4140)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3757)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2696)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2660)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2494)
at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:674)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:667)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:123)
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:344)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
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:622)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
Caused by: java.lang.NullPointerException
at com.android.ddmuilib.logcat.LogCatReceiverFactory.newReceiver(LogCatReceiverFactory.java:57)
at com.android.ddmuilib.logcat.LogCatPanel.deviceSelected(LogCatPanel.java:229)
at com.android.ddmuilib.SelectionDependentPanel.deviceSelected(SelectionDependentPanel.java:52)
at com.android.ide.eclipse.ddms.views.SelectionDependentViewPart.selectionChanged(SelectionDependentViewPart.java:67)
at com.android.ide.eclipse.ddms.DdmsPlugin$6.run(DdmsPlugin.java:690)
at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135)
... 22 more
What am I doing wrong? Any help will be appreciated.
Thank you!
TextView.setText(int) uses the resource defined as an integer in R.java.
For your purpose, you might want to cast the integers to String first.
Like:
cash.setText(playerCash + "");
Or, like #Pedro said:
cash.setText(String.valueOf(playerCash));
Docs.

Categories

Resources