【问题标题】:Smack "Must have a local (user) JID set" errorSmack“必须设置本地(用户)JID”错误
【发布时间】:2017-01-28 06:56:26
【问题描述】:

无法理解为什么这个错误频繁出现并且应用程序崩溃。

以下错误:

Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.studyboard/com.studyboard.ChatMessageActivity}: java.lang.IllegalArgumentException: Must have a local (user) JID set. Either you didn't configure one or you where not connected at least once
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2493)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2555)
       at android.app.ActivityThread.access$800(ActivityThread.java:176)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1437)
       at android.os.Handler.dispatchMessage(Handler.java:111)
       at android.os.Looper.loop(Looper.java:194)
       at android.app.ActivityThread.main(ActivityThread.java:5576)
       at java.lang.reflect.Method.invoke(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:372)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:956)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:751)
Caused by java.lang.IllegalArgumentException: Must have a local (user) JID set. Either you didn't configure one or you where not connected at least once
       at org.jivesoftware.smack.filter.IQReplyFilter.<init>(IQReplyFilter.java:94)
       at org.jivesoftware.smack.AbstractXMPPConnection.createPacketCollectorAndSend(AbstractXMPPConnection.java:690)
       at org.jivesoftware.smackx.iqlast.LastActivityManager.getLastActivity(LastActivityManager.java:239)
       at com.studyboard.utils.ChatUtil.getLastActivity(ChatUtil.java:674)
       at com.studyboard.ChatMessageActivity.initChat(ChatMessageActivity.java:339)
       at com.studyboard.ChatMessageActivity.onCreate(ChatMessageActivity.java:220)
       at android.app.Activity.performCreate(Activity.java:6005)
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1111)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2446)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2555)
       at android.app.ActivityThread.access$800(ActivityThread.java:176)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1437)
       at android.os.Handler.dispatchMessage(Handler.java:111)
       at android.os.Looper.loop(Looper.java:194)
       at android.app.ActivityThread.main(ActivityThread.java:5576)
       at java.lang.reflect.Method.invoke(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:372)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:956)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:751)

我尝试使用以下网址中给出的解决方案来解决,但在我的情况下它也不起作用。网址是:- https://community.igniterealtime.org/thread/58150

用于连接到 ejabberd 并使用 Smack 4.1 登录的代码:-

XMPPTCPConnectionConfiguration.Builder config = XMPPTCPConnectionConfiguration.builder();
    config.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
    config.setServiceName(Constants.HOST);
    config.setPort(Constants.PORT);
    config.setHost(Constants.HOST);
    config.setDebuggerEnabled(true);
    config.setSendPresence(true);
    config.setUsernameAndPassword(strUsername + "@" + Constants.HOST, strPassword);


    SASLAuthentication.blacklistSASLMechanism("SCRAM-SHA-1");
    SASLAuthentication.blacklistSASLMechanism("DIGEST-MD5");
    SASLAuthentication.unBlacklistSASLMechanism("PLAIN");
    objXmpptcpConnection = new XMPPTCPConnection(config.build());
    objXmpptcpConnection.setUseStreamManagement(true);
    objXmpptcpConnection.setUseStreamManagementResumption(true);
    try {
        objXmpptcpConnection.connect();
        System.out.println("Connected to===>" + objXmpptcpConnection.getHost());
        objXmpptcpConnection.login();

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

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

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

    }

实际错误发生在下面的函数中,它返回我正在聊天的用户的最后状态:-

   public String getLastActivity(XMPPTCPConnection objXmpptcpConnection, String strUser) {

        try {
            LastActivityManager objLastActivityManager = LastActivityManager.getInstanceFor(objXmpptcpConnection);
            LastActivity objLastActivity = null;
            $$ objLastActivity = objLastActivityManager.getLastActivity(strUser + "@" + Constants.HOST);
            System.out.println("MESSAGE:" + objLastActivity.getStatusMessage());
            System.out.println("IDLE TIME::" + objLastActivity.getIdleTime());

            return convertTime(objLastActivity.getIdleTime());

        } catch (SmackException.NoResponseException e) {
            e.printStackTrace();
            return "Offline";
        } catch (XMPPException.XMPPErrorException e) {
            e.printStackTrace();
            return "Offline";
        } catch (SmackException.NotConnectedException e) {
            e.printStackTrace();
            return "Offline";
        }

    }

我已用 $$ 符号标记错误行

【问题讨论】:

  • 请添加您的代码,否则无法提供帮助
  • @MrPk 我已经添加了我的代码,如果有任何错误请告诉我

标签: android ejabberd smack


【解决方案1】:

用户名错误:

您正在尝试与 user@server@server 连接。不要连接 Jid 部分,它是自动的。

更多,您必须指定用户的资源(例如,设备的名称,默认为 Spark)。

注意:desktop smack 可能会针对 android 使用不同的类。 也许您在身份验证方面有任何其他问题,但指定错误的 JID 可以让您“连接”而不是“登录”,并且遗漏资源会破坏某些功能。

【讨论】:

  • 调试应用程序时代码工作正常。Android 7.0 和 4.0 设备上出现此错误
  • @Anil 现在看看,让我知道
  • 让我调试应用程序
  • 我认为是一样的:JID 95% 的时间都是由基于 con 配置的 API 组成的。有很多方法可以简单地删除“@server”,但不是全部。试一试
  • 你的意思是说,我必须只将 Username 传递给 getLastActivity() 方法,而不是传递 username@HOST ,对吧?
猜你喜欢
  • 2013-03-09
  • 2023-03-16
  • 1970-01-01
  • 2018-12-14
  • 1970-01-01
  • 2021-08-30
  • 2016-05-09
  • 2015-08-04
  • 1970-01-01
相关资源
最近更新 更多