SMACK 4.1客户经理:帐户注册中的私人访问错误

时间:2015-10-03 19:00:09

标签: android xmpp smack

我在使用Smack 4.1中的客户经理处理Android时遇到了一个奇怪的错误。

以下是代码段:

        am = new AccountManager(connection);
    Map<String, String> mp = new HashMap<String, String>();
    // adding or set elements in Map by put method key and value
    // pair
    mp.put("username", "user3");
    mp.put("password", "ps3");
    mp.put("name", "user3");
    mp.put("email", "user3@user.com");
    try {
        am.createAccount("user3", "user3", mp);
    } catch (SmackException.NoResponseException e) {
        e.printStackTrace();
    } catch (XMPPException.XMPPErrorException e) {
        e.printStackTrace();
    } catch (SmackException.NotConnectedException e) {
        e.printStackTrace();
    }

我用来连接Openfire Server的代码是:

        XMPPTCPConnectionConfiguration.Builder configBuilder = XMPPTCPConnectionConfiguration.builder();
        configBuilder.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
        configBuilder.setServiceName("host_name");
        configBuilder.setHost("host_name");
        configBuilder.setPort(5222);
        configBuilder.setCompressionEnabled(false).build();

    AbstractXMPPConnection connection = new XMPPTCPConnection(configBuilder.build());

    try {
        System.out.println("connecting");
        connection.setPacketReplyTimeout(10000);
        connection.connect();
        System.out.println("connected");
        SASLAuthentication.unBlacklistSASLMechanism("PLAIN");
        SASLAuthentication.blacklistSASLMechanism("DIGEST-MD5");


    } catch (SmackException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (XMPPException e) {
        e.printStackTrace();
    }

并且运行得很完美。

确切的错误是:&#34; 错误:(66,18)错误:AccountManager(XMPPConnection)在AccountManager中具有私人访问权限&#34;

我浪费了2-3个小时试图找到它但没有得到答案。我是一个菜鸟,如果这是一个基本问题,请原谅我。也请回复,因为我被困住了,无法前进。

非常感谢时间!!

1 个答案:

答案 0 :(得分:0)

您需要从accountManager获取与您的Xmpp连接相关的instance

AccountManager ac = AccountManager.getInstance(XMPPConnection connection)