w is obviously null when you try to access it.
Your problem is that you're using a JFrame where a modal dialog or JOptionPane would work better. If you used the dialog, then your calling code would wait until the dialog is no longer visible, and at that time, w would likely no longer be null.
Edit
You ask:
and can you elaborate on why JFrame will not work? Just telling me that its my problem doesnt help very much -
What? I didn't just tell you that it was the problem -- I offered a solution -- use a modal JDialog. Again, a modal dialog will freeze code flow from the calling code when it is launched, and the calling code will remain frozen until the dialog is no longer visible.
Your problem is that your attempting to use the w variable before the dialog window has had a chance to do anything with it. A JFrame does not pause the calling code's program flow, and that is causing your problem.
Edit 2
So a JFrame doesn't actually execute the code until it is closed?
No, not true at all. Look where your w is given a valid reference -- in your JFrame's button's ActionListener. So w will not receive a valid reference until the ActionListener has been called, which only will happen when the button is pressed. Your code as written tries to use w immediately before the user has had any chance to push your pop-up's buttons. If you used a modal JDialog instead, and made sure that w was set prior to closing the dialog, your code could work.
But a JDialog will do so as it gets the input?
Nope. See above.