Smack "Must have a local (user) JID set" error
Asked Answered
D

1

10

Unable to understand why this error frequently comes and app gets crash.

Below error:

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)

I have tried to solve using the solution given in the following url,but its also not working in my case.Url is:- https://community.igniterealtime.org/thread/58150

Code using for connecting to ejabberd and login using 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();

    }

Actual error occurs in below function which returns me last status of user for with I am chatting:-

   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";
        }

    }

I have marked error line with $$ symbol

Dogface answered 20/9, 2016 at 11:12 Comment(2)
please add your code or it's impossible to helpVenerate
@Venerate I have added my code,let me know if there is any errorDogface
V
0

Username it's wrong:

You are tryin to connect with user@server@server. Dont concat Jid part, it's automatic.

More, you have to specify the RESOURCE of the user (Example, the name of the device, default it's Spark).

Pay attention: desktop smack may use different classes against android. Maybe you have anyother problem with authentication but specify a bad JID can let you "connect" but not "login" and omiss the Resource brokes some functionalities.

Venerate answered 22/9, 2016 at 6:53 Comment(7)
Code working fine when I am debugging the application.This error occurs on Android 7.0 and 4.0 devicesDogface
@Anil look now and let me knowVenerate
Let me debug the applicationDogface
I think it's the same: JID it's 95% of times composed by API basing con Configuration. There are a lot of methods that simply removes "@server" but not all. Give it a tryVenerate
You mean to say,I have to pass only Username to getLastActivity() method rather than passing username@HOST , right?Dogface
yep. Jid it's JabberID, it's created by "username" + "@" + "servername". Error says JID it's invalid. Prolly you are passing "username@servername@servername" by mistakeVenerate
Let us continue this discussion in chat.Dogface

© 2022 - 2024 — McMap. All rights reserved.