1

in the Sun Java PetStore demo index.jsp file, I'm getting a Null Pointer Exception on cf

CatalogFacade cf = (CatalogFacade)getServletContext().getAttribute("CatalogFacade");
List<Tag> tags=cf.getTagsInChunk(0, 12);  <--- cf is Null

I'm using Eclipse and I don't know why CatalogFacade is null or how to debug this.
Any clue greatly appreciated.

Edit: In the CatalogFacade Class which implements ServletContextListener

public void contextInitialized(ServletContextEvent sce) {
    ServletContext context = sce.getServletContext();
    context.setAttribute("CatalogFacade", this);
}
jeff
  • 3,618
  • 9
  • 48
  • 101

1 Answers1

1

My first investigation would be to see if getServletContext().getAttribute("CatalogFacade"); returns a null.

If it does, then you've never stored a CatalogFacade object in your application. Perhaps look at storing it using getServletContext().setAttribute("CatalogFacade", cf);?

That's what I can help you with (with the little info you've provided).

Buhake Sindi
  • 87,898
  • 29
  • 167
  • 228
  • where would I make that call to setAttribute? Based on this answer here, I don't have a context but I don't know how to add something to a context. http://stackoverflow.com/questions/4381724/persistenceunit-annotation-wont-create-an-entitymanagefactory-emfnull/4382010#4382010 – jeff Dec 08 '10 at 20:12