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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:51:44+00:00 2026-05-26T23:51:44+00:00

Ive been trying to debug this for hours but I was unable to get

  • 0

Ive been trying to debug this for hours but I was unable to get why it’s happening. I have an assumption that the map returned is null? not sure really. Here is the code:

FormBean Managed Bean:

package core.smd.classes;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import java.util.Date;
import org.joda.time.DateTime;
import java.util.List;
 import java.util.ArrayList;


@ManagedBean
@SessionScoped
public class FormBean {

/** Creates a new instance of FormBean */

int counter=0;
String eventTitle;
Date startDate;
Date endDate;
String requestType;
String trainingOption;
String projectOption;
int terminals;
String lastName;
String firstName;
String middleInitials;
int badgeNo;
String networkID;
String telephoneNo;
String orgCode;
String orgName;
String justification;

public FormBean(){

}

public String getEventTitle() {
    return eventTitle;
}

public void setEventTitle(String eventTitle) {
    this.eventTitle = eventTitle;
}

public Date getEndDate() {
    return endDate;
}

public void setEndDate(Date endDate) {
    this.endDate = endDate;

}

public Date getStartDate() {
    return startDate;
}

public void setStartDate(Date startDate) {
    this.startDate = startDate;

}

public String getFirstName() {
    return firstName;
}

public void setFirstName(String firstName) {
    this.firstName = firstName;
}

public String getLastName() {
    return lastName;
}

public void setLastName(String lastName) {
    this.lastName = lastName;
}

public String getMiddleInitials() {
    return middleInitials;
}

public void setMiddleInitials(String middleInitials) {
    this.middleInitials = middleInitials;
}

public String getRequestType() {
    return requestType;
}

public void setRequestType(String requestType) {
    this.requestType = requestType;
}

public int getTerminals() {
    return terminals;
}

public void setTerminals(int terminals) {
    this.terminals = terminals;
}

public String getProjectOption() {
    return projectOption;
}

public void setProjectOption(String projectOption) {
    this.projectOption = projectOption;
}

public String getTrainingOption() {
    return trainingOption;
}

public void setTrainingOption(String trainingOption) {
    this.trainingOption = trainingOption;
}

public int getBadgeNo() {
    return badgeNo;
}

public void setBadgeNo(int badgeNo) {
    this.badgeNo = badgeNo;
}

public String getJustification() {
    return justification;
}

public void setJustification(String justification) {
    this.justification = justification;
}

public String getNetworkID() {
    return networkID;
}

public void setNetworkID(String networkID) {
    this.networkID = networkID;
}

public String getOrgCode() {
    return orgCode;
}

public void setOrgCode(String orgCode) {
    this.orgCode = orgCode;
}

public String getOrgName() {
    return orgName;
}

public void setOrgName(String orgName) {
    this.orgName = orgName;
}

public String getTelephoneNo() {
    return telephoneNo;
}

public void setTelephoneNo(String telephoneNo) {
    this.telephoneNo = telephoneNo;
}

public String createInstance(){
    Reservation rsv = new Reservation();
    boolean success = rsv.checkRange();
    counter = rsv.counter;
    if(success == true)
        return "Successful";
    else
        return "Failed!";
}

}

Then here is Reservation class:

package core.smd.classes;


import java.util.Date;
import java.util.ArrayList;
import java.util.List;
import java.util.TreeMap;
import java.util.Map;

import org.joda.time.DateTime;


public class Reservation {



public int counter;
String eventTitle;
public Date startDate;
public Date endDate;
String requestType;
public int terminals;
String lastName;
String firstName;
String middleInitials;
int badgeNo;
String networkID;
String telephoneNo;
String orgCode;
String orgName;
String trainingOption;
String projectOption;
String justification;
public TreeMap<DateTime, Integer> map = new TreeMap<DateTime, Integer>();

public Reservation(String eventTitle, Date startDate, Date endDate, String requestType, int
terminals, String lastName, String firstName, String middleInitials, int badgeNo, String
networkID, String telephoneNo, String orgCode, String trainingOption, String justification) {
    this.eventTitle = eventTitle;
    this.startDate = startDate;
    this.endDate = endDate;
    this.requestType = requestType;
    this.terminals = terminals;
    this.lastName = lastName;
    this.firstName = firstName;
    this.middleInitials = middleInitials;
    this.badgeNo = badgeNo;
    this.networkID = networkID;
    this.telephoneNo = telephoneNo;
    this.orgCode = orgCode;
    this.trainingOption = trainingOption;
    this.justification = justification;
}

public Date getEndDate() {
    return endDate;
}

public void setEndDate(Date endDate) {
    this.endDate = endDate;
}
public Reservation(){

}
public Date getStartDate() {
    return startDate;
}

public void setStartDate(Date startDate) {
    this.startDate = startDate;
}


//generate all dates for the year
public  List<DateTime> getDateRange(DateTime start, DateTime end)
{  
    List<DateTime> ret = new ArrayList<DateTime>();
    DateTime tmp = start;
    while(tmp.isBefore(end) || tmp.equals(end)) {
        ret.add(tmp);
        tmp = tmp.plusDays(1);
    }
    return ret;
}


/*This function iterates through the list of dates and store them
 in the TreeMap for further use*/
public TreeMap<DateTime, Integer> getDatesTreeMap()
{

   // List<DateTime> dateList = new ArrayList<DateTime>();
    DateTime startx = new DateTime(startDate.getTime());
    DateTime endx = new DateTime(endDate.getTime());
    //dateList = getDateRange(dateToStart, dateToEnd);

     TreeMap<DateTime, Integer> map = new TreeMap<DateTime, Integer>();


    List<DateTime> between = getDateRange(startx, endx);

    for (DateTime d : between) {
        //System.out.println(" " + d);
        map.put(d, 46);

    }

    for (Map.Entry<DateTime, Integer> entry : map.entrySet())
    {
       System.out.println(entry.getKey() + "/" + entry.getValue());
       counter++;
    }

    return map;
}

/*This function will return the number of elements/keys 
 prouced in the TreeMap hence reflecting the correct
 date generation*/
/*public static int returnCounter()
{
    TreeMap<DateTime, Integer> tree2 = getDatesTreeMap();

    return counter;
}
*/

 public boolean checkRange() {          
        //tree2 is the map containing all the dates
        TreeMap<DateTime, Integer> tree2 = getDatesTreeMap();
        //convert Date instances into DateTime
        DateTime startx = new DateTime(startDate.getTime());
        DateTime endx = new DateTime(endDate.getTime());

        //booking status
        boolean possible = false;
        //variable for testing
        int testValue = 0;
        //Booking type: 1 = Project, 2 = Training
        int bookingType = 1;
        //produces submap

        if(bookingType == 1)
        {
            //Project
            //fetch all values for keys in the map between start and end
                for (Integer capacity : tree2.subMap(startx, endx).values()) {
                    //Provides an insight into capacity accomodation possibility
                    //testValue++;
                    //check if capacity required could be accommodated
                    terminals = 20;
                    if(capacity >= terminals)
                        //yes then its possible, set to true
                        possible = true;
                    else if(capacity < terminals)
                        //not then set it to false
                        possible = false;

                }

                if(possible == true)
                {
                    //if it is possible to accomodate request
                    for (DateTime x : tree2.subMap(startx, endx).keySet()) {
                    {
                        //for dates n, update value for next operation
                        tree2.put(x, tree2.get(x) - terminals);
                    }
                }
                }else{
                 //nothing now
                }
        }else if(bookingType == 2){
            //Training
             for (Integer capacity : tree2.subMap(startx, endx).values()) {
                    //Provides an insight into capacity accomodation possibility
                    //testValue++;
                    terminals = 20;
                    if(capacity >= terminals)
                        possible = true;
                    else if(capacity < terminals)
                        possible = false;

                }

                if(possible == true)
                {
                    for (DateTime x : tree2.subMap(startx, endx).keySet()) {
                    {
                        //46 so that all seats are reserved
                        tree2.put(x, tree2.get(x) - 46);

                    }
                }
                }else{
                 //nothing now
                }

        }


        return possible;
}//end of checkRange method 

//untested method
public boolean freeReservedSeats()
{
    //A reservation instance is passed then deal with freeing the seats

    //variable created to mock reserved seats: Later this will be derived from
    //reservation instance

    int reservedSeats = 10;
    boolean seatsFreed = false;
    TreeMap<DateTime, Integer> tree2 = getDatesTreeMap();
    DateTime startx = new DateTime(startDate.getTime());
    DateTime endx = new DateTime(endDate.getTime());
    //retrieve the map to be updated
    for (DateTime x : tree2.subMap(startx, endx).keySet()) 
    {
                //this will update the dates affected by recovered seats
                tree2.put(x, tree2.get(x)+ reservedSeats);
                seatsFreed = true;
    }

 return seatsFreed;
}
}

as per the xhtml page where the data is submitted, i’ve tested that an all fields make it to the next page through getters and setters. So no worried there…
The error shown here goes like:

java.lang.NullPointerException
at core.smd.classes.Reservation.getDatesTreeMap(Reservation.java:103)
at core.smd.classes.Reservation.checkRange(Reservation.java:140)
at core.smd.classes.FormBean.createInstance(FormBean.java:178)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at javax.el.BeanELResolver.invokeMethod(BeanELResolver.java:737)
at javax.el.BeanELResolver.invoke(BeanELResolver.java:467)
at javax.el.CompositeELResolver.invoke(CompositeELResolver.java:246)
at com.sun.el.parser.AstValue.getValue(AstValue.java:111)
at com.sun.el.parser.AstValue.getValue(AstValue.java:163)

This is all I got and not sure why this is happening 🙁
Thanks in advance for support

  • 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-26T23:51:45+00:00Added an answer on May 26, 2026 at 11:51 pm

    The exception occurs in the getDatesTreeMap method. Here you are calling methods on three objects: map, startDate and endDate. Since map is clearly initialized before being used, check if startDate and/or endDate are not null inside that method.

    Edit: from your comment detailing line 103, I can deduce that indeed startDate is null. Check how the constructor of the class is called. You may be passing a null in place of startDate.

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

Sidebar

Related Questions

I've been trying to debug this problem for many hours, but to no avail.
I've been trying to debug this issue for hours upon hours but with no
I've been trying to debug this for 2 hours and i just can't explain
I've been trying to get this javascript animation to work for hours now, and
So ive been trying to debug this friggin spacing issue for the last 4
I've been trying to debug this issue for weeks now and I have made
I've been trying to debug this error for over three hours now, changing filenames,
I've been attempting to debug this all morning but can't seem to find the
I've been trying to debug a script of mine and I can't get my
I've been trying to solve this, and have been getting stuck, so I thought

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.