开发者

java.lang.NullPointerException Sun PetStore CatalogFacade

开发者 https://www.devze.com 2023-01-29 02:15 出处:网络
in the Sun Java PetStore demo index.jsp file, I\'m getting a Null Pointer Exception on cf CatalogFacade cf = (CatalogFacade)getServletContext().getAttribute(\"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 Ecl开发者_如何学Pythonipse 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).

0

精彩评论

暂无评论...
验证码 换一张
取 消