日期:2014-05-18  浏览次数:20594 次

application.jsp运行不了,急求java.lang.NullPointerException
代码如下:运行出现java.lang.NullPointerException异常

<%@   page   contentType= "text/html;charset=gb2312 "%>
<html>
<body>
<%!
void   countPeople()
{
    ServletContext   application=getServletContext();
    Integer   number=(Integer)application.getAttribute( "Count ");
    if(number==null)
    {
        number=new   Integer(1);
        application.setAttribute( "Count ",number);
    }
    else
    {
        number=new   Integer(number.intValue()+1);
        application.setAttribute( "Count ",number);
    }
}
%>

<%
if(session.isNew())
{
    countPeople();
    Integer   myNumber=(Integer)application.getAttribute( "Count ");
    session.setAttribute( "MyCount ",myNumber);
}
%>
<p>
<p>
您是第
<%
    int   a=((Integer)session.getAttribute( "MyCount ")).intValue();
%>
<%=a%>
个访问本站的客户。
</body>
</html>

------解决方案--------------------
java.lang.NullPointerException
空指针异常
看看什么值为空或没有得到
------解决方案--------------------
第4行有个!
你的countPeople()方法能运行吗?