Thanks. You are right. I figured this out after the refreshing myself on nested classes. My mistake was using 'static' for the variable declaration. -Qiao
-----Original Message----- From: Christopher Schultz [mailto:ch...@christopherschultz.net] Sent: Tuesday, January 27, 2009 6:17 PM To: Tomcat Users List Subject: Re: Inner class trouble in JSP -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Jin, Qiao Jin wrote: > Here is an example, a menu header JSP included in various pages: > > <%! > class MenuItem { > String pageURL; > String text; > > MenuItem(String url, String t) { > this.pageURL = url; > this.text = t; > } > } > > static MenuItem[] menu = new MenuItem[] { > new MenuItem("page1.jsp", "Home"), > new MenuItem("page2.jsp", "Info"), > new MenuItem("page3.jsp", "Contact") > }; > > %> Since you have static members (MenuItem[] menu), you must use a static inner class (MenuItem). Just change your declaration of the MenuItem class to be static. 'menu' is static in the test_jsp class, which means that it is initialized at class load-time (before any instances of the class have been created). MenuItem is not accessible until after an instance of test_jsp has been created, so you have a paradox. The solution is to make them both static. Or make them both non-static. Whichever you prefer. - -chris -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkl/wBEACgkQ9CaO5/Lv0PA/aQCfRMo+aplth2RJmddR1VP4DTgM 3goAn0WNvcB6ZE14aezeazQTEA9I4KcP =2LDa -----END PGP SIGNATURE----- --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org