Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6591807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:28:23+00:00 2026-05-25T17:28:23+00:00

So I have to write a program that is a flight reservation system. If

  • 0

So I have to write a program that is a flight reservation system. If I run the program normally and enter in values when prompted, nothing goes wrong, but when I use a .txt file input, I get a NullPointerException. The part of the code im getting the NullPointerException is

 public void instantiateAirplane() throws IOException{
        boolean creatingAirplane = true;
        String className= "";
        String seatFormat;
        int rowNums;
        while (creatingAirplane){
            input  = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("Enter service class name or [ENTER] to finish: ");

            className = input.readLine();
            if (className.equals("")) {
                creatingAirplane = false;
            }
            else{   
                System.out.println("Enter seating pattern: ");
                seatFormat = input.readLine();
                System.out.println("Enter number of rows: ");
                rowNums = Integer.parseInt(input.readLine());
                plane.creatSeatingChart(className, rowNums, seatFormat);
            }
        }
    }

When doing normal input, it runs like this:

C:\Users\Owner\Desktop\Math&CIS\CS151\HW1>java UserInterface planes
Enter service class name or [ENTER] to finish:
First Class
Enter seating pattern:
WAAW
Enter number of rows:
2
Enter service class name or [ENTER] to finish:
Business Class
Enter seating pattern:
WAAW
Enter number of rows:
2
Enter service class name or [ENTER] to finish:

Add [P]assenger, Add [G]roup, [C]ancel Reservations, Print [S]eating chart, Prin
t [M]anifest, [Q]uit

But when when using a .txt input, the following happens

C:\Users\Owner\Desktop\Math&CIS\CS151\HW1>java UserInterface planes < input.txt
Enter service class name or [ENTER] to finish:
Enter seating pattern:
Enter number of rows:
Enter service class name or [ENTER] to finish:
Exception in thread "main" java.lang.NullPointerException
        at UserInterface.instantiateAirplane(UserInterface.java:21)
        at UserInterface.main(UserInterface.java:123)

C:\Users\Owner\Desktop\Math&CIS\CS151\HW1>

the exception happens at the line “if (className.equals("")) {“

the input text is the follwing:

First
WAAW
2
Economy
WCAACW
3

...

I’m not sure why it doesn’t work when using an input text.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T17:28:24+00:00Added an answer on May 25, 2026 at 5:28 pm

    That readLine() method returns a null once the iterator reaches what is known as EOF or the end of file. Check to see if ClassName == null || className.Equal("")...

    Also you may want to declare input = new BufferedReader(new InputStreamReader(System.in)); out side of your loop just so you are not re-initializing the reader at each loop iteration.

    -!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to write a program that is required to run several other programs
I have to write a program that sniffs network packets (part1-the simple part). And
I have to write a Java program that tells what coins to give out
I have to write a daemon program that constantly runs in the background and
I wanted to write a program that test if two files are duplicates (have
I have been assigned wit the task to write a program that takes a
I have a program that looks like this. I need to consistently write something
I have a robot that I need to write an autonomous program for. The
I have to write a program that accepts a sequence of average daily temperatures
I have to write a program that performs highly computationally intensive calculations. The program

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.