Java NullPointerException位于:int start=Math.max(chat.first,chat.last-10);
我在JSP中有以下Java代码: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:
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*/)