Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Exception in Thread Main error when exiting
Exception in Thread Main error when exiting [message #444659] |
Tue, 19 October 2004 19:24 |
Eclipse User |
|
|
|
Originally posted by: James.Corbett.CCRA-ADRC.GC.CA
Hello:
Further to my earlier post in regards to having a Controller class... I
have managed to set up my application using the MVC methodology.
My controller creates an instance of my main form which in turn creates my
main menu from the main menu class. I have chosen to listen from my
controller class so that I can alter other classes. In order to get a
handle to my other classes I use Get methods. All appears to work until I
exit the application and get the "Exception in Thread Main". Through my
stack trace I note that the issue seems to originate in
org.eclipse.swt.widgets.Widget.addListener.
Please find below my source: Note: with in the CreateMainMenu class I am
for the moment only concerned with the aboutItem menu item as it is.
// Written by J. Corbett October 18, 2004
import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
public class TodMainController {
private TodMain3 tm3;
private void registerScreenListenersMainForm() {
this.tm3.getCmm().getAboutItem().addListener(SWT.Selection, new
Listener() {
public void handleEvent(Event e) {
System.out.println("Ok its working");
}
});
} // end of registerScreenListenerMainForm
public static void main(String[] args) {
TodMainController tmc = new TodMainController();
tmc.tm3 = new TodMain3();
//tmc.myShell = new Shell(tmc.tm3.getShell());
//tmc.myDisplay = new Display(tmc.tm3.getDisplay());
tmc.registerScreenListenersMainForm();
} // end of main
} // end of class
// Written by J. Corbett October 14, 2004
import org.eclipse.swt.*;
import org.eclipse.swt.custom.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
public class TodMain3 {
private CreateMainMenu cmm;
private CreateToolBar ctb;
private CreateStatusLabel csl;
final Display display = new Display();
Shell shell = new Shell(display);
public TodMain3(){
cmm = new CreateMainMenu(shell);
ctb = new CreateToolBar(shell);
shell.setLayout(new FormLayout());
csl = new CreateStatusLabel(shell, "hi");
SashForm form = new SashForm(shell, SWT.HORIZONTAL);
form.setLayout(new FormLayout());
FormData data = new FormData();
data.left = new FormAttachment(0);
data.right = new FormAttachment(100);
data.top = new FormAttachment(0);
data.bottom = new FormAttachment(csl.getLbl());
data = new FormData();
data.left = new FormAttachment(0);
data.right = new FormAttachment(100);
data.bottom = new FormAttachment(100);
(csl.getLbl()).setLayoutData(data);
// Composite child1 = new Composite(form, SWT.NONE;
//child1.setLayout(new FillLayout());
shell.setSize(750, 500);
shell.setLocation(25, 50);
shell.setText("Accessible TOD with SWT & JFACE version 3.0");
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
} // end of constructor
public CreateMainMenu getCmm() {
return this.cmm;
} // end of getCmm
public Display getDisplay() {
return this.display;
} // end of getDisplay
public Shell getShell() {
return this.shell;
} // end of getShell
} // end of class
// Written by J.Corbett October 14, 2004
import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
public class CreateMainMenu {
Shell myShell;
private MenuItem aboutItem;
public CreateMainMenu(Shell s) {
myShell = s;
Menu myMenu = new Menu(myShell, SWT.BAR);
myShell.setMenuBar(myMenu);
MenuItem mnuFile = new MenuItem(myMenu, SWT.CASCADE);
mnuFile.setText("&File");
Menu fileMnu = new Menu(myShell, SWT.DROP_DOWN);
mnuFile.setMenu(fileMnu);
MenuItem newItem = new MenuItem(fileMnu, SWT.CASCADE);
newItem.setText("Ne&w");
Menu subNew = new Menu(myShell, SWT.DROP_DOWN);
newItem.setMenu(subNew);
MenuItem subRegular = new MenuItem(subNew, SWT.PUSH);
subRegular.setText("Regular Salary/Ctrl+S");
subRegular.setAccelerator(SWT.CTRL+'S');
subRegular.setEnabled(false);
MenuItem subBonus = new MenuItem(subNew, SWT.PUSH);
subBonus.setText("Bonus/Ctrl+B");
subBonus.setAccelerator(SWT.CTRL+'B');
subBonus.setEnabled(false);
MenuItem subRetro = new MenuItem(subNew, SWT.PUSH);
subRetro.setText("Retroactive Pay/Ctrl+R");
subRetro.setAccelerator(SWT.CTRL+'R');
subRetro.setEnabled(false);
MenuItem subComm = new MenuItem(subNew, SWT.PUSH);
subComm.setText("Commission/Ctrl+O");
subComm.setAccelerator(SWT.CTRL+'O');
subComm.setEnabled(false);
MenuItem subAuto = new MenuItem(subNew, SWT.PUSH);
subAuto.setText("Automobile Benefits/Ctrl+U");
subAuto.setAccelerator(SWT.CTRL+'U');
subAuto.setEnabled(false);
MenuItem exitItem = new MenuItem(fileMnu, SWT.CASCADE);
exitItem.setText("E&xit");
// end of File
MenuItem mnuView = new MenuItem(myMenu, SWT.CASCADE);
mnuView.setText("&View");
Menu viewMnu = new Menu(myShell, SWT.DROP_DOWN);
mnuView.setMenu(viewMnu);
MenuItem chkToolBar = new MenuItem(viewMnu, SWT.CHECK);
chkToolBar.setText("&Tool Bar");
MenuItem chkStatusBar = new MenuItem(viewMnu, SWT.CHECK);
chkStatusBar.setText("&Status Bar");
// end of View
MenuItem mnuOption = new MenuItem(myMenu, SWT.CASCADE);
mnuOption.setText("&Options");
Menu optionMnu = new Menu(myShell, SWT.DROP_DOWN);
mnuOption.setMenu(optionMnu);
MenuItem validItem = new MenuItem(optionMnu, SWT.CASCADE);
validItem.setText("Va&lidation");
Menu subValid = new Menu(myShell, SWT.DROP_DOWN);
validItem.setMenu(subValid);
MenuItem subBN = new MenuItem(subValid, SWT.PUSH);
subBN.setText("BN");
MenuItem subSIN = new MenuItem(subValid, SWT.PUSH);
subSIN.setText("SIN");
MenuItem changeItem = new MenuItem(optionMnu, SWT.PUSH);
changeItem.setText("&Change Defaults");
// end of Options
MenuItem mnuHelp = new MenuItem(myMenu, SWT.CASCADE);
mnuHelp.setText("&Help");
Menu helpMnu = new Menu(myShell, SWT.DROP_DOWN);
mnuHelp.setMenu(helpMnu);
MenuItem indexItem = new MenuItem(helpMnu, SWT.PUSH);
indexItem.setText("&Index");
MenuItem noticeItem = new MenuItem(helpMnu, SWT.PUSH);
noticeItem.setText("&Notice");
aboutItem = new MenuItem(helpMnu, SWT.PUSH);
aboutItem.setText("&About");
} // end of constructor
public MenuItem getAboutItem() {
return this.aboutItem;
} // end of getAboutItem
} // end of class
|
|
| |
Re: Exception in Thread Main error when exiting [message #444679 is a reply to message #444659] |
Wed, 20 October 2004 13:32 |
Eclipse User |
|
|
|
Originally posted by: James.Corbett.CCRA-ADRC.GC.CA
I have a whee bit to add to my previous post. I noted in my console that
the following appears at the top of my list:
org.eclipse.swt.SWTException: Widget is disposed
Could the above be the area of issue and if so what do I need to do to my
code in order to get past this error?
Jim
Jim Corbett wrote:
> Hello:
> Further to my earlier post in regards to having a Controller class... I
> have managed to set up my application using the MVC methodology.
> My controller creates an instance of my main form which in turn creates my
> main menu from the main menu class. I have chosen to listen from my
> controller class so that I can alter other classes. In order to get a
> handle to my other classes I use Get methods. All appears to work until I
> exit the application and get the "Exception in Thread Main". Through my
> stack trace I note that the issue seems to originate in
> org.eclipse.swt.widgets.Widget.addListener.
> Please find below my source: Note: with in the CreateMainMenu class I am
> for the moment only concerned with the aboutItem menu item as it is.
> // Written by J. Corbett October 18, 2004
> import org.eclipse.swt.*;
> import org.eclipse.swt.widgets.*;
> public class TodMainController {
> private TodMain3 tm3;
> private void registerScreenListenersMainForm() {
> this.tm3.getCmm().getAboutItem().addListener(SWT.Selection, new
> Listener() {
> public void handleEvent(Event e) {
> System.out.println("Ok its working");
> }
> });
> } // end of registerScreenListenerMainForm
> public static void main(String[] args) {
> TodMainController tmc = new TodMainController();
> tmc.tm3 = new TodMain3();
> //tmc.myShell = new Shell(tmc.tm3.getShell());
> //tmc.myDisplay = new Display(tmc.tm3.getDisplay());
> tmc.registerScreenListenersMainForm();
> } // end of main
> } // end of class
> // Written by J. Corbett October 14, 2004
> import org.eclipse.swt.*;
> import org.eclipse.swt.custom.*;
> import org.eclipse.swt.layout.*;
> import org.eclipse.swt.widgets.*;
> public class TodMain3 {
> private CreateMainMenu cmm;
> private CreateToolBar ctb;
> private CreateStatusLabel csl;
> final Display display = new Display();
> Shell shell = new Shell(display);
> public TodMain3(){
> cmm = new CreateMainMenu(shell);
> ctb = new CreateToolBar(shell);
> shell.setLayout(new FormLayout());
> csl = new CreateStatusLabel(shell, "hi");
> SashForm form = new SashForm(shell, SWT.HORIZONTAL);
> form.setLayout(new FormLayout());
> FormData data = new FormData();
> data.left = new FormAttachment(0);
> data.right = new FormAttachment(100);
> data.top = new FormAttachment(0);
> data.bottom = new FormAttachment(csl.getLbl());
> data = new FormData();
> data.left = new FormAttachment(0);
> data.right = new FormAttachment(100);
> data.bottom = new FormAttachment(100);
> (csl.getLbl()).setLayoutData(data);
> // Composite child1 = new Composite(form, SWT.NONE;
> //child1.setLayout(new FillLayout());
> shell.setSize(750, 500);
> shell.setLocation(25, 50);
> shell.setText("Accessible TOD with SWT & JFACE version 3.0");
> shell.open ();
> while (!shell.isDisposed ()) {
> if (!display.readAndDispatch ()) display.sleep ();
> }
> display.dispose ();
> } // end of constructor
> public CreateMainMenu getCmm() {
> return this.cmm;
> } // end of getCmm
> public Display getDisplay() {
> return this.display;
> } // end of getDisplay
> public Shell getShell() {
> return this.shell;
> } // end of getShell
> } // end of class
> // Written by J.Corbett October 14, 2004
> import org.eclipse.swt.*;
> import org.eclipse.swt.widgets.*;
> public class CreateMainMenu {
> Shell myShell;
> private MenuItem aboutItem;
> public CreateMainMenu(Shell s) {
> myShell = s;
> Menu myMenu = new Menu(myShell, SWT.BAR);
> myShell.setMenuBar(myMenu);
> MenuItem mnuFile = new MenuItem(myMenu, SWT.CASCADE);
> mnuFile.setText("&File");
> Menu fileMnu = new Menu(myShell, SWT.DROP_DOWN);
> mnuFile.setMenu(fileMnu);
> MenuItem newItem = new MenuItem(fileMnu, SWT.CASCADE);
> newItem.setText("Ne&w");
> Menu subNew = new Menu(myShell, SWT.DROP_DOWN);
> newItem.setMenu(subNew);
> MenuItem subRegular = new MenuItem(subNew, SWT.PUSH);
> subRegular.setText("Regular Salary/Ctrl+S");
> subRegular.setAccelerator(SWT.CTRL+'S');
> subRegular.setEnabled(false);
> MenuItem subBonus = new MenuItem(subNew, SWT.PUSH);
> subBonus.setText("Bonus/Ctrl+B");
> subBonus.setAccelerator(SWT.CTRL+'B');
> subBonus.setEnabled(false);
> MenuItem subRetro = new MenuItem(subNew, SWT.PUSH);
> subRetro.setText("Retroactive Pay/Ctrl+R");
> subRetro.setAccelerator(SWT.CTRL+'R');
> subRetro.setEnabled(false);
> MenuItem subComm = new MenuItem(subNew, SWT.PUSH);
> subComm.setText("Commission/Ctrl+O");
> subComm.setAccelerator(SWT.CTRL+'O');
> subComm.setEnabled(false);
> MenuItem subAuto = new MenuItem(subNew, SWT.PUSH);
> subAuto.setText("Automobile Benefits/Ctrl+U");
> subAuto.setAccelerator(SWT.CTRL+'U');
> subAuto.setEnabled(false);
> MenuItem exitItem = new MenuItem(fileMnu, SWT.CASCADE);
> exitItem.setText("E&xit");
> // end of File
> MenuItem mnuView = new MenuItem(myMenu, SWT.CASCADE);
> mnuView.setText("&View");
> Menu viewMnu = new Menu(myShell, SWT.DROP_DOWN);
> mnuView.setMenu(viewMnu);
> MenuItem chkToolBar = new MenuItem(viewMnu, SWT.CHECK);
> chkToolBar.setText("&Tool Bar");
> MenuItem chkStatusBar = new MenuItem(viewMnu, SWT.CHECK);
> chkStatusBar.setText("&Status Bar");
> // end of View
> MenuItem mnuOption = new MenuItem(myMenu, SWT.CASCADE);
> mnuOption.setText("&Options");
> Menu optionMnu = new Menu(myShell, SWT.DROP_DOWN);
> mnuOption.setMenu(optionMnu);
> MenuItem validItem = new MenuItem(optionMnu, SWT.CASCADE);
> validItem.setText("Va&lidation");
> Menu subValid = new Menu(myShell, SWT.DROP_DOWN);
> validItem.setMenu(subValid);
> MenuItem subBN = new MenuItem(subValid, SWT.PUSH);
> subBN.setText("BN");
> MenuItem subSIN = new MenuItem(subValid, SWT.PUSH);
> subSIN.setText("SIN");
> MenuItem changeItem = new MenuItem(optionMnu, SWT.PUSH);
> changeItem.setText("&Change Defaults");
> // end of Options
> MenuItem mnuHelp = new MenuItem(myMenu, SWT.CASCADE);
> mnuHelp.setText("&Help");
> Menu helpMnu = new Menu(myShell, SWT.DROP_DOWN);
> mnuHelp.setMenu(helpMnu);
> MenuItem indexItem = new MenuItem(helpMnu, SWT.PUSH);
> indexItem.setText("&Index");
> MenuItem noticeItem = new MenuItem(helpMnu, SWT.PUSH);
> noticeItem.setText("&Notice");
> aboutItem = new MenuItem(helpMnu, SWT.PUSH);
> aboutItem.setText("&About");
> } // end of constructor
> public MenuItem getAboutItem() {
> return this.aboutItem;
> } // end of getAboutItem
> } // end of class
|
|
|
Re: Exception in Thread Main error when exiting [message #444694 is a reply to message #444678] |
Wed, 20 October 2004 15:30 |
Eclipse User |
|
|
|
Originally posted by: James.Corbett.CCRA-ADRC.GC.CA
Veronica:
Many thanks, it works. I believe my issue began when I started adding the
controller class after the fact.
Veronika Irvine wrote:
> The application is calling registerScreenListenersMainForm after the event
> loop has terminated (event loop is found in constructor of TodMain3). When
> the event loop terminates, all widgets are disposed and calling any API on a
> disposed widget will result in the "Widget is Disposed " error. I think you
> should move the event loop out of TodMain3 and into your main method like
> this:
> public static void main(String[] args) {
> TodMainController tmc = new TodMainController ();
> tmc.tm3 = new TodMain3();
> //tmc.myShell = new Shell(tmc.tm3.getShell());
> //tmc.myDisplay = new Display(tmc.tm3.getDisplay());
> tmc.registerScreenListenersMainForm();
> Shell shell = tmc.tm3.getShell();
> Display display = tmc.tm3.getDisplay();
> while (!shell.isDisposed ()) {
> if (!display.readAndDispatch ()) display.sleep ();
> }
> display.dispose ();
> } // end of main
|
|
|
Goto Forum:
Current Time: Sat Apr 27 00:57:41 GMT 2024
Powered by FUDForum. Page generated in 0.04225 seconds
|