title: while loop in Java code for netbeans
body: <pre><code>import java.util.ArrayList;
  import javax.swing.JOptionPane;
  
  public class MainApp {
  
      public static void main(String[] args) {
  
          ArrayList&lt;Product&gt; cart = new ArrayList&lt;Product&gt;();
  
          String s1 = JOptionPane
                  .showInputDialog("Please enter the quantity of the product you have selected");
  
          int r = Integer.parseInt(s1);
  
          String s2 = JOptionPane
                  .showInputDialog("Please enter the name of the product");
  
          String s3 = JOptionPane
                  .showInputDialog("Please enter the price of the product");
          double d1 = Double.parseDouble(s3);
  
          for (int i = 0; i &lt; r; i++) {
  
              Product p1 = new Product();
              p1.setName(s2);
              p1.setPrice(d1);
  
              cart.add(p1);
  
          }
  
          double total_price = 0;
          for (int i = 0; i &lt; cart.size(); i++) {
              total_price = total_price + cart.get(i).getPrice();
          }
  
          JOptionPane.showMessageDialog(null, cart.toString()
                  + "The total price of all the products in the cart is : "
                  + total_price + " KD", "Shopping Information",
                  JOptionPane.INFORMATION_MESSAGE);
  
          cart.removeAll(cart);
  
          JOptionPane.showMessageDialog(null, "Thank you for shopping with us! ",
                  "Prompt", JOptionPane.INFORMATION_MESSAGE);
  
          String s4 = JOptionPane
                  .showInputDialog("Would you like to add items to your cart");
  
          while (s4 != "stop") {
  
              String s5 = JOptionPane
                      .showInputDialog("Please enter the name of the product");
  
              String s6 = JOptionPane
                      .showInputDialog("Please enter the price of the product");
              double d2 = Double.parseDouble(s6);
  
              Product p2 = new Product();
  
              p2.setName(s5);
              p2.setPrice(d2);
  
              cart.add(p2);
  
              String s7 = JOptionPane
                      .showInputDialog("Would you like to add more items?");
              if (s7 == "No" || s7 == "no")
                  s4 = "stop";
  
          }
  
          JOptionPane.showMessageDialog(null, cart.toString(), "Cart Details",
                  JOptionPane.INFORMATION_MESSAGE);
  
      }
  
  }
  </code></pre>
  
  <p>Everything works fine up until the while loop... somehow I cant get it to work for me. When I enter 'No' or 'no' at the end, the loop keeps running and doesn't stop until I enter space for string questions. It just gives me the following error at the end:</p>
  
  <pre><code>Exception in thread "main" java.lang.NullPointerException
      at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1008)
      at java.lang.Double.parseDouble(Double.java:540)
      at mainapp.MainApp.main(MainApp.java:66)
  Java Result: 1
  BUILD SUCCESSFUL (total time: 41 seconds)
  </code></pre>