NullPointerException when pressing JOptionPane Cancel button : <p>I am writing a program to choose between different shape and then input the values (e.g. radius) to calculate the volume of the shape using JOptionPane, I did some input validation, but the problem is whenever I press the cancel button of the JOptionPane.showInputDialog, the program crash with the following error, 
where is the problem comes from? And how can I solve it? Thanks!</p>

<pre><code>while(choice.equalsIgnoreCase("y")) { 
    .......

    if (n== JOptionPane.YES_OPTION)
    {

        while (notDone) {
              try { 
              radiusStr = JOptionPane.showInputDialog("Please enter the radius of the sphere");
              radius = Double.parseDouble(radiusStr);
              notDone = false;
              }
              catch (NumberFormatException e ){
                    JOptionPane.showMessageDialog(null, "Input error!  Please enter a number.");
                    continue;
                  }
              volume = new CircularVolume(radius);
</code></pre>
