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 7706947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:14:15+00:00 2026-06-01T00:14:15+00:00

Alright, I’ve been getting a NPE that I can’t figure out and it’s driving

  • 0

Alright, I’ve been getting a NPE that I can’t figure out and it’s driving me absolutely batty. I’ve got a linked list of Reservation objects and a 2d array of booleans to keep track of the available seats:

class ResList
{
    private Reservation head;
    private boolean [][] seats;

    ResList()
    {
        head = null; //empty list
        boolean[][] seats = new boolean[5][25];
    }

I’ve also got a method isAvailable() to determine whether a seat is available:

boolean isAvailable(int f, int s)
    {        
        if(f<0 || f>4 || s < 0 || s > 24)
            return false;
        else
            return !seats[f][s]; // this line throws the NPE
    }

But when I do this:

jcbSeat = new JComboBox();        
        for(int i = start; i <= stop; i++)
        {        
            if(list.isAvailable(selectedFlight, i))
                jcbSeat.addItem(i+1);
        }

I get a NPE where noted. I added some debugging lines to the ResList constructor, and can access seats[][] there just fine, but when I execute the method, ka-boom: NPE. What is going on here?

  • 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-06-01T00:14:16+00:00Added an answer on June 1, 2026 at 12:14 am

    Your constructor is initializing a local variable seats, not the instance variable seats.
    Try with :

    ResList()
    {
       head = null; //empty list
       seats = new boolean[5][25];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Alright so my program is getting the user's input to figure out the prime
Alright, I'm trying to figure out why I can't understand how to do this
Alright, so I am currently trying to find all strings in a list that
Alright, I understand that this problem has been asked a lot of times at
Alright, this one's got me seriously stumped, after trying things out for hours with
Alright, I found out in this question that polling sockets does not scale, so
Alright so i need to open a .txt file that will be created in
Alright, this is driving me nuts because my regex is working on Rubular, but
Alright so I have been looking around (on SO and Google) to see if
Alright, so I got this code for gluLookAt: lookAt = new Vector3f(-player.pos.x, -player.pos.y, -player.pos.z);

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.