Timestamp[] lastreply = new Timestamp[100];
replyr = lastreplyr[i].getTime();
System.out.println("Replyr: "+replyr);
lastreply[count].setTime(replyr);
System.out.println("lastreply: "+lastreply[count]);
控制台:
Replyr: 1321116689000
java.lang.NullPointerException
at website.web.InboxReader.getLastReply(InboxReader.java:937)
at website.web.InboxReader.main(InboxReader.java:55)
为什么lastreply 为空?代码中,计数从0开始。
谢谢。
最佳答案
这就是问题:
lastreply[count].setTime(replyr);
lastreply[count]
为 null,因为 Timestamp 是一个对象。
当您实例化一个对象数组时,所有值都是null
。在开始使用对象之前,您需要先插入对对象的引用。
关于java - setTime() 抛出空指针异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8117575/