Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Awkward thing happens when I call shell.open() on a certain computer (the program crashes)
icon5.gif  Awkward thing happens when I call shell.open() on a certain computer [message #498555] Tue, 17 November 2009 13:22 Go to next message
Alexandra Niculai is currently offline Alexandra NiculaiFriend
Messages: 84
Registered: July 2009
Member
Hi

I have created a class that extends Dialog. It also has a method in it, called public void open()
{
shell = new Shell(getParent(), getStyle());
		shell.setText(getText());
		// shell.setSize(315, 400);
		importImages(shell);
		createContents(shell);
		if (bmImage != null) {
			shell.setImage(bmImage);
		}
		shell.pack();
		shell.open();
		Display display = getParent().getDisplay();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
} 


So, when an event occurs, the program creates an object of this class and then calls the open() method on it. Everything goes well on my computer(Windows XP), on other computers with XP, also on Windows Vista and 7.
The problem is on this one specific computer. I've used logging to see exactly where the problem is and the program crashes when calling shell.open(). Here is the stack trace above shell.open():
null
isActive at line -1 in class org.eclipse.swt.widgets.Control
updateModal at line -1 in class org.eclipse.swt.widgets.Shell
setModalShell at line -1 in class org.eclipse.swt.widgets.Display
setVisible at line -1 in class org.eclipse.swt.widgets.Shell
open at line -1 in class org.eclipse.swt.widgets.Shell
open at line 81


Could anyone please help me understand what's happening? The computer with the problem is running on Windows XP, service pack 3 and has no problem opening other Dialogs, only this one.

[Updated on: Tue, 17 November 2009 13:23]

Report message to a moderator

Re: Awkward thing happens when I call shell.open() on a certain computer [message #498588 is a reply to message #498555] Tue, 17 November 2009 15:08 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
Hi,

You're saying there's a Null Pointer Exception happening in
Control.isActive(), right? Can you provide the stack trace that's being
dumped, to see which line has the problem? Otherwise it's difficult to know
why this would fail on one machine in particular. Does the machine have any
unusual Windows features/add-ons running that the others don't? Is it using
the Classic theme instead of the default XP theme?

Grant


"Alexandra Niculai" <alexa.sunshine@gmail.com> wrote in message
news:hdu82l$vgi$1@build.eclipse.org...
> Hi
>
> I have created a class that extends Dialog. It also has a method in it,
called public void open()
> {
> shell = new Shell(getParent(), getStyle());
> shell.setText(getText());
> // shell.setSize(315, 400);
> importImages(shell);
> createContents(shell);
> if (bmImage != null) {
> shell.setImage(bmImage);
> }
> shell.pack();
> shell.open();
> Display display = getParent().getDisplay();
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch()) {
> display.sleep();
> }
> }
> }
>
> So, when an event occurs, the program creates an object of this class and
then calls the open() method on it. Everything goes well on my
computer(Windows XP), on other computers with XP, also on Windows Vista and
7.
> The problem is on this one specific computer. I've used logging to see
exactly where the problem is and the program crashes when calling
shell.open(). Here is the stack trace above shell.open():
> null
> isActive at line -1 in class org.eclipse.swt.widgets.Control
> updateModal at line -1 in class org.eclipse.swt.widgets.Shell
> setModalShell at line -1 in class org.eclipse.swt.widgets.Display
> setVisible at line -1 in class org.eclipse.swt.widgets.Shell
> open at line -1 in class org.eclipse.swt.widgets.Shell
> open at line 81
>
> Could anyone help me understand what's happening? The computer with the
problem is running on Windows XP, service pack 3 and has no problem opening
other Dialogs, only this one.
Re: Awkward thing happens when I call shell.open() on a certain computer [message #498590 is a reply to message #498588] Tue, 17 November 2009 15:36 Go to previous messageGo to next message
Alexandra Niculai is currently offline Alexandra NiculaiFriend
Messages: 84
Registered: July 2009
Member
I can't get the exact line because the machine on which this happens is not mine, but I think it's using a Classic theme instead of the XP theme.
Re: Awkward thing happens when I call shell.open() on a certain computer [message #498790 is a reply to message #498555] Wed, 18 November 2009 16:06 Go to previous messageGo to next message
Alexandra Niculai is currently offline Alexandra NiculaiFriend
Messages: 84
Registered: July 2009
Member
The owner of the computer having this behavior has changed the theme, it's not the classic theme anymore, but the problem persists.
icon1.gif  Re: Awkward thing happens when I call shell.open() on a certain computer [message #500502 is a reply to message #498588] Thu, 26 November 2009 12:57 Go to previous messageGo to next message
Alexandra Niculai is currently offline Alexandra NiculaiFriend
Messages: 84
Registered: July 2009
Member
OK, I managed to get the line numbers for that code. I also noticed that this happens with most of the swt dialogs on that computer, but who knows, there may be other computers having the same behavior. Here it is

java.lang.NullPointerException
    at org.eclipse.swt.widgets.Control.isActive(Control.java:1583)
    at org.eclipse.swt.widgets.Shell.updateModal(Shell.java:1912)
    at org.eclipse.swt.widgets.Display.setModalDialog(Display.java:4192)
    at org.eclipse.swt.widgets.MessageBox.open(MessageBox.java:200)


Could anyone please help me solve this?

Greetings
Alexandra.
Re: Awkward thing happens when I call shell.open() on a certain computer [message #500692 is a reply to message #500502] Fri, 27 November 2009 14:29 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
Hi,

MessageBox does not appear in the original code snippet that was provided,
so the details of your case are still not clear. Questions:

- Which SWT version are you using? (to determine the line with the NPE)
- what is the style of the parent shell that is passed to your class'
constructor?
- what is the style (if any) that is passed to your class' constructor?

If possible, a more complete snippet showing the failure would be ideal
(template: http://www.eclipse.org/swt/faq.php#whatisasnippet ).

Grant


"Alexandra Niculai" <alexa.sunshine@gmail.com> wrote in message
news:heltva$1u7$1@build.eclipse.org...
> OK, I managed to get the line numbers for that code. I also noticed that
this happens with most of the swt dialogs on that computer, but who knows,
there may be other computers having the same behavior. Here it is
>
> java.lang.NullPointerException
> at org.eclipse.swt.widgets.Control.isActive(Control.java:1583)
> at org.eclipse.swt.widgets.Shell.updateModal(Shell.java:1912)
> at org.eclipse.swt.widgets.Display.setModalDialog(Display.java: 4192)
> at org.eclipse.swt.widgets.MessageBox.open(MessageBox.java:200)
>
> Could anyone please help me solve this?
>
> Greetings
> Alexandra.
Re: Awkward thing happens when I call shell.open() on a certain computer [message #500720 is a reply to message #500692] Fri, 27 November 2009 17:35 Go to previous messageGo to next message
Alexandra Niculai is currently offline Alexandra NiculaiFriend
Messages: 84
Registered: July 2009
Member
Thank you for replying! Here is the name of the swt jar I'm using:
org.eclipse.win32.win32.x86_3.5.1.v555a.jar
There is no style for the shell. And here is a snippet:

package test;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;

public class Main {

	Image arrow;
	Image img;

	public static void main(String[] args) {
		Display display = new Display();
		final Shell myShell = new Shell(display);

		FormLayout formLayout = new FormLayout();
		myShell.setLayout(formLayout);

		Button button = new Button(myShell, SWT.PUSH);
		button.setText("Push");

		button.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent event) {
				MessageBox mb = new MessageBox(myShell, SWT.ICON_QUESTION
						| SWT.YES | SWT.NO | SWT.CANCEL);
				mb.setText("Question");
				mb.setMessage("Do you want to add a new operation?");
				int val = mb.open();// this is where it has a problem
			}
		});

		myShell.open();
		while (!myShell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
		display.dispose();
	}

}


The problem is when trying to open the MessageBox dialog.
Re: Awkward thing happens when I call shell.open() on a certain computer [message #501258 is a reply to message #500720] Tue, 01 December 2009 16:48 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
I've looked into this, and my guess is that somehow another shell is being
disposed during the process of opening the MessageBox (eg.- in a listener?).
However I don't see the problem on my machine, and I'm pretty sure there's
nothing in your snippet that should cause this to happen, so I think you
need to debug your app on the machine that's showing the problem. Try the
following:

- retrieve the two swt plugins into your workspace (eg.- File > Import... >
Plug-ins and Fragments > Projects with source folders > ...)
- put a breakpoint at the beginning of Display.setModalDialog()
- debug your app, trigger the bad condition, hit the breakpoint
-> look at the result of the getShells() call, are any of them disposed?
getShells() should not return any disposed Shells. Assuming not...
- now put a breakpoint at the beginning of Control.isActive(), which will be
hit when Shell.updateModal() is invoked for each of these Shells
-> is the receiver now disposed (but presumably was not before)? If so,
how did it get disposed? A disposed Shell should be the only time that a
Shell's display is null

Even having looked at swt's code in this area I was not able to change the
snippet to fail on my machine, so I don't think I can investigate further.
However feel free to follow up here with observations/questions that arise
from debugging on the problem machine.

Grant


"Alexandra Niculai" <alexa.sunshine@gmail.com> wrote in message
news:hep2l9$34a$1@build.eclipse.org...
> Thank you for replying! Here is the name of the swt jar I'm using:
> org.eclipse.win32.win32.x86_3.5.1.v555a.jar
> There is no style for the shell. And here is a snippet:
>
> package test;
>
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.events.SelectionAdapter;
> import org.eclipse.swt.events.SelectionEvent;
> import org.eclipse.swt.graphics.Image;
> import org.eclipse.swt.layout.FormLayout;
> import org.eclipse.swt.widgets.Button;
> import org.eclipse.swt.widgets.Display;
> import org.eclipse.swt.widgets.MessageBox;
> import org.eclipse.swt.widgets.Shell;
>
> public class Main {
>
> Image arrow;
> Image img;
>
> public static void main(String[] args) {
> Display display = new Display();
> final Shell myShell = new Shell(display);
>
> FormLayout formLayout = new FormLayout();
> myShell.setLayout(formLayout);
>
> Button button = new Button(myShell, SWT.PUSH);
> button.setText("Push");
>
> button.addSelectionListener(new SelectionAdapter() {
> @Override
> public void widgetSelected(SelectionEvent event) {
> MessageBox mb = new MessageBox(myShell, SWT.ICON_QUESTION
> | SWT.YES | SWT.NO | SWT.CANCEL);
> mb.setText("Question");
> mb.setMessage("Do you want to add a new operation?");
> int val = mb.open();// this is where it has a problem
> }
> });
>
> myShell.open();
> while (!myShell.isDisposed()) {
> if (!display.readAndDispatch()) {
> display.sleep();
> }
> }
> display.dispose();
> }
>
> }
>
>
> The problem is when trying to open the MessageBox dialog.
Re: Awkward thing happens when I call shell.open() on a certain computer [message #512295 is a reply to message #501258] Thu, 04 February 2010 15:24 Go to previous message
Alexandra Niculai is currently offline Alexandra NiculaiFriend
Messages: 84
Registered: July 2009
Member
Hi

Some more information about this: it only happens with modal dialogs. All the other dialogs are ok. I tested this with a custom Dialog. Whenever I was setting the style of the Dialog to SWT.APPLICATION_MODAL, I was getting an exception. It always worked on my machine. Both machines are Windows XP sp 3.
Here is a new exception that was thrown when trying to open a MessageBox on that machine:
PLUS FIN: THROW
java.lang.NullPointerException
    at org.eclipse.swt.widgets.Control.isActive(Control.java:1583)
    at org.eclipse.swt.widgets.Shell.updateModal(Shell.java:1912)
    at org.eclipse.swt.widgets.Display.setModalDialog(Display.java:4192)
    at org.eclipse.swt.widgets.MessageBox.open(MessageBox.java:200)
    at teexmaprove.tools.Actions.terminate(Actions.java:57)

I can't figure out why.
Previous Topic:Deploy an SWT app
Next Topic:Button selection event
Goto Forum:
  


Current Time: Tue Apr 16 07:36:54 GMT 2024

Powered by FUDForum. Page generated in 0.89840 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top