Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Pressing Cancel in FileDialog close entire application (Using SWT)

  1. #1
    Junior Member
    Join Date
    May 2013
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Pressing Cancel in FileDialog close entire application (Using SWT)

    HI,

    when I open a file dialog from my application and press the cancel button located within the file dialog, it just closes the file dialog as expected, if I repeat the process, it closes the entire application, that would be my main shell which has my menubar, as well as a number of other things and the application window which holds the button the activates the file dialog.

    this is the error log that it gives

    ImportWindow is the application window
    AppMainShell is the class the creates the main Shell
    I can include code, but wasnt sure what to put here.

    I have included an image to give the basic idea of what it looks like

    pic.jpg

    #
    java.lang.NullPointerException
    at app.GUIConstructionModule.ImportWindow$4.widgetSelected(ImportWindow.java:324)
    at org.eclipse.swt.widgets.TypedListener.handleEvent(Unknown Source)
    at org.eclipse.swt.widgets.EventTable.sendEvent(Unknown Source)
    at org.eclipse.swt.widgets.Widget.sendEvent(Unknown Source)
    at org.eclipse.swt.widgets.Display.runDeferredEvents(Unknown Source)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Unknown Source)
    at app.GUIConstructionModule.ImportWindow.openWindow(ImportWindow.java:74)
    at app.GUIConstructionModule.ImportWindow.<init>(ImportWindow.java:41)
    at app.GUIConstructionModule.AppMenu$2.widgetSelected(AppMenu.java:181)
    at org.eclipse.swt.widgets.TypedListener.handleEvent(Unknown Source)
    at org.eclipse.swt.widgets.EventTable.sendEvent(Unknown Source)
    at org.eclipse.swt.widgets.Widget.sendEvent(Unknown Source)
    at org.eclipse.swt.widgets.Display.runDeferredEvents(Unknown Source)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Unknown Source)
    at app.GUIConstructionModule.AppMainShell.setupWindow(AppMainShell.java:30)
    at app.GUIConstructionModule.AppMainShell.<init>(AppMainShell.java:16)
    at app.ConstructApp.<init>(ConstructApp.java:24)
    at app.ConstructApp.main(ConstructApp.java:36)
    java.lang.NullPointerException
    at app.GUIConstructionModule.ImportWindow$6.widgetSelected(ImportWindow.java:352)
    at org.eclipse.swt.widgets.TypedListener.handleEvent(Unknown Source)
    at org.eclipse.swt.widgets.EventTable.sendEvent(Unknown Source)
    at org.eclipse.swt.widgets.Widget.sendEvent(Unknown Source)
    at org.eclipse.swt.widgets.Display.runDeferredEvents(Unknown Source)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Unknown Source)
    at app.GUIConstructionModule.AppMainShell.setupWindow(AppMainShell.java:30)
    at app.GUIConstructionModule.AppMainShell.<init>(AppMainShell.java:16)
    at app.ConstructApp.<init>(ConstructApp.java:24)
    at app.ConstructApp.main(ConstructApp.java:36)




    I appreciate any help


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Pressing Cancel in FileDialog close entire application (Using SWT)

    java.lang.NullPointerException
    at app.GUIConstructionModule.ImportWindow$4.widgetSel ected(ImportWindow.java:324)
    There is a variable with a null value on line 324. Look at line 324 in the your source and see what variable is null. Then backtrack in the code to see why that variable does not have a valid value.
    If you can not tell which variable it is, add a println just before line 324 and print out the values of all the variables on that line.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    May 2013
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Pressing Cancel in FileDialog close entire application (Using SWT)

    Cool thanks you nailed it, so obvious in retrospect, I appreciate your input, this is the segment that was crashing the application



    mainfileButton.addSelectionListener(new SelectionAdapter() {
     
    				 public void widgetSelected(SelectionEvent e) {
     
     
    					 main = new FileDialog(shell, SWT.OPEN);
    					 String path = main.open();
     
     
    					 /*
    					 if(!path.isEmpty()){
     
    						 mainfilePathHolder.setText (path);
     
    					 }
    					 */
    				 }
    			});

    when my if statement gets validated, if cancel is pushed, path is null.
    The weird thing remains,for some reason, it would only crash after repeating the error on the second time, but yes Im going to chuck in a try, catch statement to solve it.

    Thank you very much!

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Pressing Cancel in FileDialog close entire application (Using SWT)

    going to chuck in a try, catch statement
    An if statement would be better.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    May 2013
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Pressing Cancel in FileDialog close entire application (Using SWT)

    Cool, changed it to an if statement, works great, thank you

Similar Threads

  1. Cancel button ..??
    By smasm in forum Loops & Control Statements
    Replies: 3
    Last Post: November 5th, 2011, 06:12 AM
  2. How to set cancel button ASAP please
    By smasm in forum Object Oriented Programming
    Replies: 1
    Last Post: October 1st, 2011, 08:29 AM
  3. WHY AM I HAVING TO PUT THE ENTIRE FILE PATH?!?!
    By CameronHussey in forum What's Wrong With My Code?
    Replies: 1
    Last Post: August 7th, 2011, 05:32 AM
  4. FileDialog with JFrame
    By nigi10 in forum AWT / Java Swing
    Replies: 3
    Last Post: December 3rd, 2010, 10:20 AM
  5. Run Or Cancel Java Thread !
    By byrodi in forum The Cafe
    Replies: 11
    Last Post: November 3rd, 2010, 09:04 AM