2010-12-02 3 views
1

、私はEclipseを使用していcfのjava.lang.NullPointerException日PetStoreをCatalogFacadeは、Sun Java PetStoreをデモindex.jspファイルで

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

にNULLポインタ例外を取得していますし、私は知りませんなぜCatalogFacadeがnullか、これをデバッグする方法。
何か手がかりが大変ありがとうございます。

編集:implements ServletContextListener

public void contextInitialized(ServletContextEvent sce) { 
    ServletContext context = sce.getServletContext(); 
    context.setAttribute("CatalogFacade", this); 
} 
+0

あなたの 'ServletContext'は属性" CatalogFacade "を持っていますか? – birryree

+0

web.xmlにエントリがあるかどうかを確認する場合は、noを入力します。 – jeff

答えて

1

私の最初の調査はgetServletContext().getAttribute("CatalogFacade");nullを返すかどうかを確認することですCatalogFacadeクラスで 。

もしそうなら、アプリケーションにCatalogFacadeオブジェクトを保存したことはありません。おそらくgetServletContext().setAttribute("CatalogFacade", cf);を使用してそれを格納するのを見ますか?

これは私があなたに提供した小さな情報であなたを助けることができるものです。

+0

どこでsetAttributeを呼び出すのですか?ここの答えに基づいて、私は文脈を持っていませんが、文脈に何かを加える方法はわかりません。 http://stackoverflow.com/questions/4381724/persistenceunit-annotation-wont-create-an-entitymanagefactory-emfnull/4382010#4382010 – jeff

関連する問題