Java NullPointerException位于:int start=Math.max(chat.first,chat.last-10);

Java NullPointerException位于:int start=Math.max(chat.first,chat.last-10);,java,Java,我在JSP中有以下Java代码: 21: ChatState chat = (ChatState)application.getAttribute(ChatConstants.APP_STATE); 22: // assert(chat != null); 23: 24: int start = Math.max(chat.first, chat.last-10); 25: for (int i=start; i<chat.last; i++) { 26:

我在JSP中有以下Java代码:

21:     ChatState chat = (ChatState)application.getAttribute(ChatConstants.APP_STATE);
22:     // assert(chat != null);
23: 
24:     int start = Math.max(chat.first, chat.last-10);
25:     for (int i=start; i<chat.last; i++) {
26:     out.println(i + "User Says: " + chat.chat.get(i));
27:     }

您的聊天对象在此处显示为空

请查收

1.web.xml文件,如果在其中初始化了应用程序状态变量

2.你写作的职位-

application.setAttribute(/*some code snippet*/)

3.您可以检查这些属性是否从任何属性文件设置


这些检查可能会为您提供问题的指针。

第21行返回的
chat
实例似乎是
null
。您如何设置应用程序属性
chatcants.APP_STATE
?如果
chat.first
chat.last
返回
Integer
而不是
int
null
Integer
不能自动装箱到
0
,并且在对其进行数学运算时会抛出NPE。
application.setAttribute(/*some code snippet*/)