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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:35:38+00:00 2026-06-01T16:35:38+00:00

I am having trouble creating and using objects to type List<Integer> . When I

  • 0

I am having trouble creating and using objects to type List<Integer>. When I run the following code, I get a NullPointerException because the Object isn’t initialized.

import java.util.List;

public class RBTree {

    public static class Tree {
        public List<Integer> parent;
        public List<Integer> right;
        public List<Integer> left;
        public List<Integer> data;
        public List<Boolean> black;
    }

    public static void main (String[] args){
        Tree rb =new Tree();                
        rb.data.add(-1);
        rb.left.add(-1);
        rb.right.add(-1);
        rb.parent.add(-1);
        rb.black.add(Boolean.TRUE);
    }
}

The compiler also gives me errors unless I add static to the public static class Tree line, but I don’t want Tree to be static i.e. immutable. I need to be able to use a Tree more-or-less like a struct in C.

  • 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-01T16:35:39+00:00Added an answer on June 1, 2026 at 4:35 pm

    you forgot to create the actual list objects:

    public List<Integer> parent = new ArrayList<Integer>();
    public List<Integer> right = new ArrayList<Integer>();
    public List<Integer> left = new ArrayList<Integer>();
    public List<Integer> data = new ArrayList<Integer>();
    public List<Boolean> black = new ArrayList<Boolean>();
    

    if you don’t do this, then your lists are null and access a property or method on someting which is not there produces a NullPointerException.

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

Sidebar

Related Questions

I am having trouble creating an entity using inout ports. I tried writing the
I'm having trouble creating an Access table using VBA, then accessing it via open-recordset.
I'm having little trouble creating a script working with URLs. I'm using urllib.urlopen() to
I am having some serious trouble creating a WPF TreeView with an Object databinding.
I'm having trouble creating a new model row in the database using ActiveRecord in
I am using Aptana Studio 3 and having trouble creating a rails project in
I am creating a Guitar Hero Clone using C# and am having some trouble
I am having trouble creating an export of my database using an org.dbunit.database.QueryDataSet. When
I'm having trouble creating multiple xml requests using php's curl_multi_exec. The problem is that
I am having trouble in creating and displaying multiple game objects on the screen

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.