if (isFirstInitialization) {
packetWriter = new PacketWriter(this);
packetReader = new PacketReader(this); // If debugging is enabled, we should start the thread that will listen for
// all packets and then log them.
if (config.isDebuggerEnabled()) {
addPacketListener(debugger.getReaderListener(), null);
if (debugger.getWriterListener() != null) {
addPacketSendingListener(debugger.getWriterListener(), null);
}
}
}
else {
packetWriter.init();
packetReader.init();
} // Start the packet writer. This will open a XMPP stream to the server
packetWriter.startup();
// Start the packet reader. The startup() method will block until we
// get an opening stream packet back from server.
packetReader.startup(); // Make note of the fact that we're now connected.
connected = true; // Start keep alive process (after TLS was negotiated - if available)
packetWriter.startKeepAliveProcess();Exception in thread "Thread-33" java.lang.NullPointerException
at org.jivesoftware.smack.XMPPConnection.initConnection(XMPPConnection.java:595)
at org.jivesoftware.smack.XMPPConnection.connectUsingConfiguration(XMPPConnection.java:548)
at org.jivesoftware.smack.XMPPConnection.connect(XMPPConnection.java:974)
at net.sf.kraken.protocols.xmpp.XMPPSession$1.run(XMPPSession.java:277)
at java.lang.Thread.run(Thread.java:619)
// Start keep alive process (after TLS was negotiated - if available)
packetWriter.startKeepAliveProcess();在这一行中出现了空指针错误,太古怪了.在这句代码之前,还有很多使用到packetWriter的地方呢,并且该对象是在上面被创建的.
这个问题并不是必现,只是当大并发的时候会出现,不知其原因,想请高手解答.
// Start keep alive process (after TLS was negotiated - if available)
packetWriter.startKeepAliveProcess();因为每次都会到这一句才会出现null指针,而上面使用到的地方,也并没有修改packetWriter值的操作.
并且这个问题,一旦出现了之后,后面就一直会出现空指针.不会有成功的地方.