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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:16:38+00:00 2026-06-14T19:16:38+00:00

I am getting NullPointerException in the following code : private Map<String,List<Entry>> Days; private void

  • 0

I am getting NullPointerException in the following code :

private Map<String,List<Entry>> Days;
private void intializeDays() {
    //Iterate over the DayOfWeek enum and put the keys in Map
    for(DayOfWeek dw : EnumSet.range(DayOfWeek.MONDAY,DayOfWeek.SUNDAY)){
    List<Entry> entries = null;
    Days.put(dw.toString().toLowerCase(),entries);
    }
}

I think its because of

List<Entry> entries = null;

but then how do I create an empty list and add it to a map ?

  • 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-14T19:16:40+00:00Added an answer on June 14, 2026 at 7:16 pm

    You must initialize your map:

    private Map<String,List<Entry>> Days = new HashMap<>();
    

    Note that you can use

    List<Entry> entries = new ArrayList <Entry> ();
    

    and add to the map, instead of adding a null.

    About NullPointerException

    Thrown when an application attempts to use null in a case where an object is required. These include:

    Calling the instance method of a null object.
    Accessing or modifying the field of a null object.
    Taking the length of null as if it were an array.
    Accessing or modifying the slots of null as if it were an array.
    Throwing null as if it were a Throwable value.
    Applications should throw instances of this class to indicate other illegal uses of the null object.
    

    Since you did not initialize you Map object when you did this:

    Days.put(dw.toString().toLowerCase(),entries);
    

    you get NullPointerException because you are “Accessing or modifying the field of a null object.”.

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

Sidebar

Related Questions

I'm getting a strange NullPointerException, evidently thrown by the following line of code: Iterator<Note>
Im getting nullpointerexception for the following code: I have SMS of more than 160
I am getting the java.lang.NullPointerException on createTabContent for the following code. There are two
Can anyone tell me why am i getting error message java.lang.NullPointerException in following code??
I'm getting a NullPointerException in the following Hibernate code. I've marked the line with
i am writing code for btree algorithms. i am getting NullPointerException . why???? please
I'm getting a nullpointer exception in the following code in my application : @Override
Good day, Any idea why i could be getting a NullPointerException in the following
I'm getting the following NullPointerException while trying to use the Play FBConnect module: Caused
I'm getting a NPE occasionally on the following code: I'm a rookie in hibernate

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.