Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: What am I doing wrong here?

  1. #1
    Junior Member
    Join Date
    Jan 2022
    Posts
    19
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Question What am I doing wrong here?

    Hello,

    I'm working on a project, where a person enters a bakkery. If the person has a VIP pass it will stand in row 1, if not, the person will stand in row 2. I need to use the ArrayList in order to register the persons in the bakery.

    The class of Person registers the name and VIP pass. I'm trying to code it like below, but I get the NullPointerException in the line row1.add(name);

    What am I doing wrong, or is there a different way to get the person into the right row?

    Thanks in advance!

    public class Bakery
    {
        // instance variables
        private String name;
        private ArrayList<Person> client;
        private ArrayList<Person> row1;
        private ArrayList<Person> row2;
     
        /**
         * Constructor for objects of class Bakery
         */
        public Bakery (String name)
        {
            this.name = name;
            client = new ArrayList<Person> ();
        }
     
        public void enterBakery (Person name)
        {
            if (name.hasVIPpass() == true)
            {
                row1.add(name);
            }
     
            else 
            {
                row2.add(name);
            }
        }
    Last edited by F_VRBRG; May 2nd, 2022 at 07:13 AM.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: What am I doing wrong here?

    Where is row1 given a value? If it is not assigned a value, it will have a null value.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jan 2022
    Posts
    19
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: What am I doing wrong here?

    Hi Norm,

    Thanks, that is it.

    Problem solved

Similar Threads

  1. Replies: 4
    Last Post: February 21st, 2021, 11:03 AM
  2. Am I doing something wrong?
    By emkash01 in forum What's Wrong With My Code?
    Replies: 9
    Last Post: February 22nd, 2019, 11:17 AM
  3. What have I done wrong?
    By Kkbob in forum Other Programming Languages
    Replies: 3
    Last Post: September 29th, 2014, 07:07 AM
  4. Replies: 4
    Last Post: March 6th, 2014, 05:14 PM
  5. What's wrong?
    By Lukas in forum What's Wrong With My Code?
    Replies: 39
    Last Post: November 5th, 2013, 09:35 AM