2016-09-20 41 views
9

無法理解爲什麼經常出現此錯誤並且應用程序崩潰。Smack「必須有一個本地(用戶)JID設置」錯誤

以下錯誤:

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) 

我曾嘗試使用下面的鏈接中給出的解決方案來解決,但它也沒有在我case.Url工作是: -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(); 

    } 

實際誤差RNS我的用戶最後狀態與我聊天: -

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

    } 

我已經打上$$符號

+0

請加你的代碼或不可能幫到 – MrPk

+0

@MrPk我加了我的代碼,讓我知道是否有任何錯誤 –

回答

0

用戶名這是錯的錯誤行:

你試着與用戶連接@服務器@服務器。不要concat Jid部分,它是自動的。

更多的,你必須指定用戶的RESOURCE(例如設備名稱,默認爲Spark)。

注意:desktop smack可能會針對android使用不同的類。 也許你有任何其他認證問題,但指定一個錯誤的JID可以讓你「連接」而不是「登錄」,並省略資源製造一些功能。

+1

當我調試應用程序時,代碼工作正常。在Android 7.0和4.0設備上發生此錯誤 –

+0

@Anil現在看看,讓我知道 – MrPk

+0

讓我調試應用程序 –

相關問題