Asmack Search Friends report null pointer solution

Source: Internet
Author: User
Tags vcard

First Kind


In Connection.connect (); Before establishing a connection

Call this method

Smackandroid.init (this);

The second Kind

public static void Configure (Providermanager pm) {//Private Data storagepm.addiqprovider ("Query", "Jabber:iq:private", New Privatedatamanager.privatedataiqprovider ()); timetry {pm.addiqprovider ("query", "Jabber:iq:time", Class.forName ("Org.jivesoftware.smackx.packet.Time"));} catch (ClassNotFoundException e) {LOG.W ("testclient", "Can ' t load class for Org.jivesoftware.smackx.packet.Time");}// Roster Exchangepm.addextensionprovider ("X", "Jabber:x:roster", New Rosterexchangeprovider ()); Message Eventspm.addextensionprovider ("x", "Jabber:x:event", New Messageeventprovider ()); Chat Statepm.addextensionprovider ("Active", "Http://jabber.org/protocol/chatstates", new Chatstateextension.provider ());p M.addextensionprovider ("Composing", "Http://jabber.org/protocol/chatstates", new Chatstateextension.provider ());p M.addextensionprovider ("Paused", "http://jabber.org/protocol/chatstates", new Chatstateextension.provider ());p M.addextensionprovider ("Inactive", "http://jabber.org/protocol/chAtstates ", New Chatstateextension.provider ());p M.addextensionprovider (" Gone "," http://jabber.org/protocol/ Chatstates ", New Chatstateextension.provider ()); Xhtmlpm.addextensionprovider ("HTML", "Http://jabber.org/protocol/xhtml-im", New Xhtmlextensionprovider ()); Group Chat Invitationspm.addextensionprovider ("x", "Jabber:x:conference", New Groupchatinvitation.provider ()); Service Discovery # itemspm.addiqprovider ("Query", "Http://jabber.org/protocol/disco#items", new Discoveritemsprovider ()); Service Discovery # infopm.addiqprovider ("Query", "Http://jabber.org/protocol/disco#info", new Discoverinfoprovider ()); Data Formspm.addextensionprovider ("x", "Jabber:x:data", New Dataformprovider ()); MUC Userpm.addextensionprovider ("x", "Http://jabber.org/protocol/muc#user", New Mucuserprovider ()); MUC adminpm.addiqprovider ("Query", "Http://jabber.org/protocol/muc#admin", New Mucadminprovider ()); MUC ownerpm.addiqprovider ("Query", "Http://jabber.org/protocol/muc#owner", newMucownerprovider ()); Delayed Deliverypm.addextensionprovider ("x", "Jabber:x:delay", New Delayinformationprovider ()); versiontry {pm.addiqprovider ("query", "Jabber:iq:version", Class.forName (" Org.jivesoftware.smackx.packet.Version "));} catch (ClassNotFoundException e) {//Not sure-what's happening here}//Vcardpm.addiqprovider ("VCard", "Vcard-temp", new Vcardprovider ()); Offline Message requestspm.addiqprovider ("Offline", "Http://jabber.org/protocol/offline", new Offlinemessagerequest.provider ()); Offline Message indicatorpm.addextensionprovider ("Offline", "Http://jabber.org/protocol/offline", new Offlinemessageinfo.provider ()); Last Activitypm.addiqprovider ("Query", "Jabber:iq:last", New Lastactivity.provider ()); User searchpm.addiqprovider ("Query", "Jabber:iq:search", New Usersearch.provider ()); Sharedgroupsinfopm.addiqprovider ("Sharedgroup", "Http://www.jivesoftware.org/protocol/sharedgroup", new Sharedgroupsinfo.provider ()); jep-33:extended Stanza AddressiNgpm.addextensionprovider ("Addresses", "http://jabber.org/protocol/address", New Multipleaddressesprovider ()); Filetransferpm.addiqprovider ("Si", "http://jabber.org/protocol/si", New Streaminitiationprovider ()); Pm.addiqprovider ("Query", "Http://jabber.org/protocol/bytestreams", New Bytestreamsprovider ()); Privacypm.addiqprovider ("Query", "Jabber:iq:privacy", New Privacyprovider ());p m.addiqprovider ("command", "http:/ /jabber.org/protocol/commands ", New Adhoccommanddataprovider ());p M.addextensionprovider (" malformed-action "," http ://jabber.org/protocol/commands ", New Adhoccommanddataprovider.malformedactionerror ());p M.addextensionprovider (" Bad-locale "," Http://jabber.org/protocol/commands ", New Adhoccommanddataprovider.badlocaleerror ()); Pm.addextensionprovider ("Bad-payload", "Http://jabber.org/protocol/commands", new Adhoccommanddataprovider.badpayloaderror ());p M.addextensionprovider ("Bad-sessionid", "http://jabber.org/ Protocol/commands ", New Adhoccommanddataprovider.badsessioniderror ());p M.addextensionprovider ("session-expired", "Http://jabber.org/protocol/commands", new Adhoccommanddataprovider.sessionexpirederror ());}

In Connection.connect (); Before establishing a connection

Call

Configure (Providermanager.getinstance ());
/** * Query User * * @param connection * @param serverdomain * @param userName * @return * @throws xmppexception */public Stat IC list<userbean> searchusers (xmppconnection connection,string userName) throws Xmppexception {LIST&L T          userbean> results = new arraylist<userbean> ();          SYSTEM.OUT.PRINTLN ("query begins ...") +connection.gethost () +connection.getservicename ()););          Usersearchmanager USM = new Usersearchmanager (connection); Form searchform = Usm.getsearchform ("Search.")          +connection.getservicename ());          Form answerform = Searchform.createanswerform ();          Answerform.setanswer ("Username", true);          Answerform.setanswer ("Search", userName); Reporteddata data = Usm.getsearchresults (Answerform, "search."           +connection.getservicename ());           Iterator<row> it = data.getrows ();           row row = null;           UserBean user = null;      while (It.hasnext ()) {user = new UserBean ();         row = It.next ();               User.setusername (Row.getvalues ("Username"). Next (). ToString ());               User.setname (Row.getvalues ("Name"). Next (). ToString ());               User.setemail (Row.getvalues ("Email"). Next (). ToString ());               System.out.println (Row.getvalues ("Username"). Next ());               System.out.println (Row.getvalues ("Name"). Next ());               System.out.println (Row.getvalues ("Email"). Next ());               Results.add (user);         If there is, there is a return, username must be non-empty, the other two if there is set, must not be empty} toast.maketext (context, results.size () + "", (). Show ();      return results;   }


Asmack Search Friends report null pointer solution

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.