0

I have been stuck for days, my program keeps crashing. Please help. I am trying to obtain a jOptionPane dialog box that displays the first and last name, the boxes show up, but then my system crashes.

package rarjavazonapp;

import javax.swing.JOptionPane;
import java.util.Scanner;


/**l
 *
 * @author Rita Dennis
 */
public class RarJavazonApp {

/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
    // TODO code application logic here
    Scanner sc = new Scanner(System.in);

    //COLLECT INFORMATION USING JOPTIONPANE


    String firstName = Validator.getValidFirstName(JOptionPane.showInputDialog( "Enter First Name"));
    String last = Validator.getValidFirstName(JOptionPane.showInputDialog( "Enter Last Name"));
    String Street = Validator.getValidFirstName(JOptionPane.showInputDialog( "Enter Street"));
    String State = Validator.getValidFirstName(JOptionPane.showInputDialog( "Enter State"));
    String Zip = Validator.getValidFirstName(JOptionPane.showInputDialog("Enter Zip"));
    String Phone = Validator.getValidFirstName(JOptionPane.showInputDialog( "Enter Phone"));
    String Membership = Validator.getValidFirstName(JOptionPane.showInputDialog( "Enter Membership"));


    //Do the same for the other variables
    String lastName = "";
    String street = "";
    String city = "";
    String state = "";
    String zip = "";
    String phone = "";
    String membership = "";

    //CREATE A NEW CUSTOMER OBJECT (uncomment line below)
    Customer customer = new Customer(firstName, lastName, street, city, state, zip, phone, membership);


    //CREATE NEW ORDER OBJECT
    Order order = new Order();

    //SET ORDER CUSTOMER
    order.setOrderCustomer(customer);

    //LOOP TO COLLECT PRODUCTS SELECTED BY USER AND THEIR QUANTITIES
    do {
        //CREATE MENU OBJECT
        Menu menu = new Menu();

        //Get the items from the menu class, and load them into the
        //JOptionPane menu
        String menuItems[] = menu.getMenuDescriptions();

        int intCode = 0;
        intCode = JOptionPane.showOptionDialog(null, "Select an Option",
                "Menu Items", JOptionPane.YES_NO_CANCEL_OPTION,
                JOptionPane.QUESTION_MESSAGE, null, menuItems, menuItems[0]);

        //RETURN PRODUCT FROM MENU
        Product product = menu.getMenu()[intCode];

        //PROMPT USER TO ENTER QUANTITY
        String qty = JOptionPane.showInputDialog("Enter Quantity");

        //ADD PRODUCT AND QUANTITY TO ORDER
        order.setOrderProduct(product, Integer.parseInt(qty));

    } while (JOptionPane.showConfirmDialog(null,
            "Enter More Products?",
            "User Selection",
            JOptionPane.YES_NO_OPTION,
            JOptionPane.QUESTION_MESSAGE,
            null) != JOptionPane.NO_OPTION);

    //CREATE A NEW JAVAZON STORE
    JavaZon jz = new JavaZon();

    //ADD THE ORDER TO THE STORE
    jz.setOrder(order);

    //ASSIGN A CLERK TO THE ORDER
    jz.setClerk();

    //PROCESS ORDER
    jz.processOrder();

    //DISPLAY THE RESULT
    JOptionPane.showMessageDialog(null, jz.getReceipt());
  }
}
M. Prokhorov
  • 3,894
  • 25
  • 39
Zara Z.
  • 23
  • 7
  • 1
    Please clarify what you mean by "crashes" -- does it throw an exception? If so, show the exception stacktrace method. Does it shut the computer down? Cus at you? Make you write bad checks? What? – Hovercraft Full Of Eels Apr 19 '17 at 20:37
  • Thank you it shows me the following: Exception in thread "main" java.lang.NullPointerException at javax.swing.plaf.basic.BasicOptionPaneUI.addButtonComponents(BasicOptionPaneUI.java:673) – Zara Z. Apr 19 '17 at 20:44
  • The heuristic for debugging a NullPointerException is almost always the same: You should critically read your exception's stacktrace to find the line of code at fault, the line that throws the exception, and then inspect that line carefully, find out which variable is null, and then trace back into your code to see why. You will run into these again and again, trust me. – Hovercraft Full Of Eels Apr 19 '17 at 20:47
  • In that case, instead of posting full text of your program here, please search that exception in some search engine (like Google) and see what causes it. A `NullPointerException` is typically the most common and the easiest exception to fix. Also, when asking the question you ideally want to provide as little code as possible to explain your problem. – M. Prokhorov Apr 19 '17 at 20:47
  • Specifically you will want to create and post a [mcve] a minimal program that runs and demonstrates the problem. – Hovercraft Full Of Eels Apr 19 '17 at 20:58
  • I have tried debugging, but I am still not clear on what problem I have. I am gonna have to talk to my professor. Thank You – Zara Z. Apr 19 '17 at 21:05
  • If you read the Q&A that we linked this question to, it explains how to debug NPEs. For a start, you need to learn to read a stacktrace. (You haven't shown us the most important line of the stacktrace for solving this problem ... which suggests that you don't known how to read them yet.) Perhaps your professor will explain that to you. – Stephen C Apr 20 '17 at 01:34

0 Answers0