简体   繁体   中英

java.lang.NullPointerException Sun PetStore CatalogFacade

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);
}

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM