4 Replies Latest reply: Dec 18, 2006 12:22 AM by 807607 RSS

    Exception in thread "main" java.lang.NullPointerException - How to Fix?

    807607
      I'm getting an error code:
      Exception in thread "main" java.lang.NullPointerException

      I don't know what I'm doing wrong. I have bolded the line JCreator has told me was causing the error. Any help?

      import java.util.Scanner;

      class NicePrice {

      public static void main(String args[]) {
      Scanner myScanner = new Scanner(System.in);
      int age;
      double price = 0.00;
      char reply;
      boolean isKid, isSenior, hasCoupon, hasNoCoupon;

      System.out.print("How old are you? ");
      age = myScanner.nextInt();

      System.out.print("Have a coupon? (Y/N) ");
      reply = myScanner.findInLine(".").charAt(0);

      isKid = age < 12;
      isSenior = age >= 65;
      hasCoupon = reply == 'Y' || reply == 'y';
      hasNoCoupon = reply == 'N' || reply == 'n';

      if (!isKid && !isSenior) {
      price = 9.25;
      }
      if (isKid || isSenior) {
      price = 5.25;
      }

      if (hasCoupon) {
      price -= 2.00;
      }
      if (!hasCoupon && !hasNoCoupon) {
      System.out.println("Huh?");
      }

      System.out.print("Please pay $");
      System.out.print(price);
      System.out.print(". ");
      System.out.println("Enjoy the show!");
      }
      }