2016-09-20 11 views
9

Không thể hiểu tại sao lỗi này thường đến và ứng dụng bị lỗi.Smack "Phải có một bộ JID địa phương (người dùng)" lỗi

Dưới lỗi:

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) 

Tôi đã cố gắng để giải quyết bằng cách sử dụng giải pháp được đưa ra trong url sau đây, mà còn của nó không làm việc trong case.Url của tôi là: -https://community.igniterealtime.org/thread/58150

Mã sử ​​dụng để kết nối với ejabberd và đăng nhập bằng 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(); 

    } 

Lỗi thực tế xảy ra ở hàm bên dưới mà retu RNS tôi tình trạng cuối cùng của người dùng cho với tôi trò chuyện: -

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

    } 

Tôi đã đánh dấu dòng lỗi với $$ biểu tượng

+0

hãy thêm mã của bạn hoặc không thể giúp – MrPk

+0

@MrPk Tôi đã thêm mã của mình, hãy cho tôi biết nếu có bất kỳ lỗi nào –

Trả lời

0

Tên đăng nhập đó là sai:

Bạn đang tryin để kết nối với người sử dụng @ server @ server. Không concat phần Jid, nó tự động.

Thêm, bạn phải chỉ định NGUỒN TÀI NGUYÊN của người dùng (Ví dụ: tên thiết bị, mặc định là Spark).

Chú ý: máy tính để bàn có thể sử dụng các lớp khác nhau chống lại Android. Có thể bạn có vấn đề khác với xác thực nhưng chỉ định một JID xấu có thể cho phép bạn "kết nối" nhưng không "đăng nhập" và bỏ qua các tài nguyên brokes một số chức năng.

+1

Mã hoạt động tốt khi tôi gỡ lỗi ứng dụng. Lỗi này xảy ra trên thiết bị Android 7.0 và 4.0 –

+0

@Anil nhìn bây giờ và cho tôi biết – MrPk

+0

Hãy để tôi gỡ lỗi ứng dụng –

Các vấn đề liên quan