0
回答
关于Smack登录时的空指针问题急求解决方法
利用AWS快速构建适用于生产的无服务器应用程序,免费试用12个月>>>   

OSC 各位好:

   这个问题在项目中一直存在,一直没找到合适的解决方法。

环境:Vysper+ smack3.2.2

链接服务器和登录代码如下:

ConnectionConfiguration config = new ConnectionConfiguration(
				XMPP_SERVER, XMPP_SERVER_PORT, XMPP_SERVER);
		config.setCompressionEnabled(true);
        config.setSASLAuthenticationEnabled(true);
        SASLAuthentication.supportSASLMechanism("PLAIN", 0);

		connection = new XMPPConnection(config);


		int i = 0;
		while (!connection.isConnected()) {
			try {
				Thread.sleep(i * 2000);
				connection.connect();
			} catch (Exception ex) {
				i++;
				i = Math.min(i, 20);
				Debug.logInfo("Connect to XMPP server(" + XMPP_SERVER
						+ ") failed, wait for " + i + " seconds to retry.",
						module);
			}
		}
		System.err.println("connection: "+connection.isConnected());
		connection.login(userName, password);
		roster = connection.getRoster();
		Presence presence = new Presence(Presence.Type.available);

出现的bug如下:

 

INFO   | jvm 1    | 2012/08/15 11:46:18 | java.lang.NullPointerException
INFO   | jvm 1    | 2012/08/15 11:46:18 | 	at org.jivesoftware.smack.XMPPConnection.sendPacket(XMPPConnection.java:450)
INFO   | jvm 1    | 2012/08/15 11:46:18 | 	at org.jivesoftware.smack.SASLAuthentication.send(SASLAuthentication.java:567)
INFO   | jvm 1    | 2012/08/15 11:46:18 | 	at org.jivesoftware.smack.sasl.SASLMechanism.authenticate(SASLMechanism.java:125)
INFO   | jvm 1    | 2012/08/15 11:46:18 | 	at org.jivesoftware.smack.sasl.SASLMechanism.authenticate(SASLMechanism.java:93)
INFO   | jvm 1    | 2012/08/15 11:46:18 | 	at org.jivesoftware.smack.SASLAuthentication.authenticate(SASLAuthentication.java:319)
INFO   | jvm 1    | 2012/08/15 11:46:18 | 	at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:203)
INFO   | jvm 1    | 2012/08/15 11:46:18 | 	at org.jivesoftware.smack.Connection.login(Connection.java:348)
INFO   | jvm 1    | 2012/08/15 11:46:18 | 	at com.siteview.svdb.ofbiz.VysperGateway.xmppLogin(VysperGateway.java:108)
INFO   | jvm 1    | 2012/08/15 11:46:18 | 	at com.siteview.svdb.ofbiz.VysperGateway.start(VysperGateway.java:179)
INFO   | jvm 1    | 2012/08/15 11:46:18 | 	at org.ofbiz.base.container.ContainerLoader.start(ContainerLoader.java:230)
INFO   | jvm 1    | 2012/08/15 11:46:18 | 	at org.ofbiz.base.start.Start.startStartLoaders(Start.java:294)
INFO   | jvm 1    | 2012/08/15 11:46:18 | 	at org.ofbiz.base.start.Start.start(Start.java:273)
INFO   | jvm 1    | 2012/08/15 11:46:18 | 	at org.ofbiz.base.start.Start.main(Start.java:119)
INFO   | jvm 1    | 2012/08/15 11:46:18 | 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
INFO   | jvm 1    | 2012/08/15 11:46:18 | 	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
INFO   | jvm 1    | 2012/08/15 11:46:18 | 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
INFO   | jvm 1    | 2012/08/15 11:46:18 | 	at java.lang.reflect.Method.invoke(Unknown Source)
INFO   | jvm 1    | 2012/08/15 11:46:18 | 	at org.tanukisoftware.wrapper.WrapperSimpleApp.run(WrapperSimpleApp.java:240)
INFO   | jvm 1    | 2012/08/15 11:46:18 | 	at java.lang.Thread.run(Unknown Source)
INFO   | jvm 1    | 2012/08/15 11:46:18 | 
INFO   | jvm 1    | 2012/08/15 11:46:18 | WrapperSimpleApp: Encountered an error running main: java.lang.NullPointerException
INFO   | jvm 1    | 2012/08/15 11:46:18 | java.lang.NullPointerException
INFO   | jvm 1    | 2012/08/15 11:46:18 | 	at org.jivesoftware.smack.XMPPConnection.sendPacket(XMPPConnection.java:450)
INFO   | jvm 1    | 2012/08/15 11:46:18 | 	at org.jivesoftware.smack.NonSASLAuthentication.authenticate(NonSASLAuthentication.java:69)
INFO   | jvm 1    | 2012/08/15 11:46:18 | 	at org.jivesoftware.smack.SASLAuthentication.authenticate(SASLAuthentication.java:362)
INFO   | jvm 1    | 2012/08/15 11:46:18 | 	at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:203)
INFO   | jvm 1    | 2012/08/15 11:46:18 | 	at org.jivesoftware.smack.Connection.login(Connection.java:348)
INFO   | jvm 1    | 2012/08/15 11:46:18 | 	at com.siteview.svdb.ofbiz.VysperGateway.xmppLogin(VysperGateway.java:108)
INFO   | jvm 1    | 2012/08/15 11:46:18 | 	at com.siteview.svdb.ofbiz.VysperGateway.start(VysperGateway.java:179)
INFO   | jvm 1    | 2012/08/15 11:46:18 | 	at org.ofbiz.base.container.ContainerLoader.start(ContainerLoader.java:230)
INFO   | jvm 1    | 2012/08/15 11:46:18 | 	at org.ofbiz.base.start.Start.startStartLoaders(Start.java:294)
INFO   | jvm 1    | 2012/08/15 11:46:18 | 	at org.ofbiz.base.start.Start.start(Start.java:273)
INFO   | jvm 1    | 2012/08/15 11:46:18 | 	at org.ofbiz.base.start.Start.main(Start.java:119)
INFO   | jvm 1    | 2012/08/15 11:46:18 | 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
INFO   | jvm 1    | 2012/08/15 11:46:18 | 	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
INFO   | jvm 1    | 2012/08/15 11:46:18 | 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
INFO   | jvm 1    | 2012/08/15 11:46:18 | 	at java.lang.reflect.Method.invoke(Unknown Source)
INFO   | jvm 1    | 2012/08/15 11:46:18 | 	at org.tanukisoftware.wrapper.WrapperSimpleApp.run(WrapperSimpleApp.java:240)
INFO   | jvm 1    | 2012/08/15 11:46:18 | 	at java.lang.Thread.run(Unknown Source)

网上找了一些资料,换Smack版本也不行

参考资料:http://community.igniterealtime.org/message/185164#185164

                http://oneminutedistraction.wordpress.com/2010/07/26/discovering-services/

                http://issues.igniterealtime.org/browse/SMACK-264

如果有哪位遇到过同样的问题请指教一下,非常感谢!

举报
忠平
发帖于5年前 0回/1K+阅
顶部