在xmpp中无法识别登录方法

时间:2014-09-11 13:01:09

标签: java android smack asmack

我正在尝试用android中的smack库连接到openfire服务器。但在登录方法中出错。

public void performLogin(String username, String password) throws XMPPException {
        if (connection!=null && connection.isConnected()) {
            connection.login(username, password);
        }
    }

错误是

The method login(String, String) from the type XMPPConnection refers to the missing type SaslException

这里有什么问题?

2 个答案:

答案 0 :(得分:0)

Smack 4.0无法在Android上运行,请使用aSmack 4.0.

Smack 4.1将在Android上运行,但尚未发布。

答案 1 :(得分:0)

我们可以使用下面的代码在 xmpp 服务器中通过 smack 登录。在本例中,我们首先构建 ConnectionConfiguration 对象,然后创建 XMPPConnection 对象。

ConnectionConfiguration config = new ConnectionConfiguration(
"localhost", 5222);

XMPPConnection connection = new XMPPConnection(config);
try {
connection.connect();
} catch (XMPPException e) {

e.printStackTrace();
} 

您可以看到来源:smack client example

现在我们将使用

登录
connection.login("Username","Password");