Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/222.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法使用smack Android在openfire中创建新用户_Java_Android_Openfire_Smack - Fatal编程技术网

Java 无法使用smack Android在openfire中创建新用户

Java 无法使用smack Android在openfire中创建新用户,java,android,openfire,smack,Java,Android,Openfire,Smack,我正在尝试为android即时消息应用程序使用smack创建一个新用户,该用户将存储在openfire数据库中,但每次我运行它时,用户记录都不会显示在openfire中 创建用户活动 private void setConnection() { // Create the configuration for this new connection //this function or code given in official documention gi

我正在尝试为android即时消息应用程序使用smack创建一个新用户,该用户将存储在openfire数据库中,但每次我运行它时,用户记录都不会显示在openfire中

创建用户活动

 private void setConnection() {

        // Create the configuration for this new connection

        //this function or code given in official documention give an error in openfire run locally to solve this error
        //first off firewall
        //then follow my steps

        new Thread() {
            @Override
            public void run() {

                InetAddress addr = null;
                try {
                    // inter your ip4address now checking it
                    addr = InetAddress.getByName("192.168.23.150");
                } catch (UnknownHostException e) {
                    e.printStackTrace();
                }
                HostnameVerifier verifier = new HostnameVerifier() {
                    @Override
                    public boolean verify(String hostname, SSLSession session) {
                        return false;
                    }
                };
                DomainBareJid serviceName = null;
                try {
                    serviceName = JidCreate.domainBareFrom("localhost");
                } catch (XmppStringprepException e) {
                    e.printStackTrace();
                }
                XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()
                        .setUsernameAndPassword("admin","kalaBOOK98")
                        .setPort(9090)
                        .setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)
                        .setXmppDomain(serviceName)
                        .setHostnameVerifier(verifier)
                        .setHostAddress(addr)
                        .setDebuggerEnabled(true)
                        .build();
                Log.v(TAG,"connection configured");
                mConnection = new XMPPTCPConnection(config);
                        //now send message and receive message code here
                        AccountManager accountManager = AccountManager.getInstance(mConnection);
                        try {
                            Log.v(TAG,"Creating new user");
                            accountManager.createAccount(Localpart.from(userId),userPassword);
                        } catch (SmackException.NoResponseException e) {
                            Log.v(TAG,"Error in creating user"+e);
                            e.printStackTrace();
                        } catch (XMPPException.XMPPErrorException e) {
                            Log.v(TAG,"Error in creating user"+e);
                            e.printStackTrace();
                        } catch (SmackException.NotConnectedException e) {
                            Log.v(TAG,"Error in creating user"+e);
                            e.printStackTrace();
                        } catch (InterruptedException e) {
                            Log.v(TAG,"Error in creating user"+e);
                            e.printStackTrace();
                        } catch (XmppStringprepException e) {
                            Log.v(TAG,"Error in creating user"+e);
                            e.printStackTrace();
                        }
                    }

// Now we create the account:

// The account has been created, so we can now login

        }.start();
    }
每次我尝试运行它时,就会出现此日志错误

日志

任何帮助都将不胜感激
提前感谢

正如您在日志中看到的,您必须连接到服务器才能创建新用户。您的连接有问题,在重新连接成功之前无法创建用户。 在创建用户之前,您可以通过以下方法检查连接或身份验证状态:

connection.isAuthenticated()
connection.isConnected()
mConnection=newxmpptcpconnection(配置);
//现在在这里发送消息和接收消息代码
AccountManager=AccountManager.getInstance(mConnection);
试一试{
accountManager.createAccount(Localpart.from(userId)、userPassword);
} …
创建连接实例后,该实例未连接。这就是为什么在尝试执行需要连接的操作时会出现
NotConnectedException
。为了在XMPP服务上创建帐户,首先必须通过调用

`mConnection.connect()`.

我不是很喜欢smack和openfire,但你能试试我的样品吗
`mConnection.connect()`.