Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/384.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
java.lang.NullPointerException Sun PetStore CatalogFacade_Java_Eclipse - Fatal编程技术网

java.lang.NullPointerException Sun PetStore CatalogFacade

java.lang.NullPointerException Sun PetStore CatalogFacade,java,eclipse,Java,Eclipse,在Sun Java PetStore demo index.jsp文件中,我在cf CatalogFacade cf = (CatalogFacade)getServletContext().getAttribute("CatalogFacade"); List<Tag> tags=cf.getTagsInChunk(0, 12); <--- cf is Null 我的第一个调查是看getServletContext().getAttribute(“CatalogFacad

在Sun Java PetStore demo index.jsp文件中,我在
cf

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

我的第一个调查是看
getServletContext().getAttribute(“CatalogFacade”)
返回一个
null

如果是,那么您从未在应用程序中存储过
CatalogFacade
对象。也许可以考虑使用
getServletContext().setAttribute(“CatalogFacade”,cf)存储它


这就是我可以帮助您的(您提供的信息很少)。

我的第一个调查将是查看
getServletContext().getAttribute(“CatalogFacade”)
返回一个
null

如果是,那么您从未在应用程序中存储过
CatalogFacade
对象。也许可以考虑使用
getServletContext().setAttribute(“CatalogFacade”,cf)存储它


这就是我可以帮助您的(您提供的信息很少)。

您的
ServletContext
是否有属性“catalogafacade”?如果您询问web.xml中的条目中是否有,则否。您的
ServletContext
是否有属性“catalogacade”?如果您询问web.xml中的条目中是否有,那么不,我在哪里调用setAttribute呢?根据这里的答案,我没有上下文,但我不知道如何向上下文添加内容。我在哪里调用setAttribute?根据这里的答案,我没有上下文,但我不知道如何向上下文添加内容。
public void contextInitialized(ServletContextEvent sce) {
    ServletContext context = sce.getServletContext();
    context.setAttribute("CatalogFacade", this);
}