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://", new Chatstateextension.provider ());p M.addextensionprovider ("Composing", "Http://", new Chatstateextension.provider ());p M.addextensionprovider ("Paused", "", new Chatstateextension.provider ());p M.addextensionprovider ("Inactive", " ", New Chatstateextension.provider ());p M.addextensionprovider (" Gone "," Chatstates ", New Chatstateextension.provider ()); Xhtmlpm.addextensionprovider ("HTML", "Http://", New Xhtmlextensionprovider ()); Group Chat Invitationspm.addextensionprovider ("x", "Jabber:x:conference", New Groupchatinvitation.provider ()); Service Discovery # itemspm.addiqprovider ("Query", "Http://", new Discoveritemsprovider ()); Service Discovery # infopm.addiqprovider ("Query", "Http://", new Discoverinfoprovider ()); Data Formspm.addextensionprovider ("x", "Jabber:x:data", New Dataformprovider ()); MUC Userpm.addextensionprovider ("x", "Http://", New Mucuserprovider ()); MUC adminpm.addiqprovider ("Query", "Http://", New Mucadminprovider ()); MUC ownerpm.addiqprovider ("Query", "Http://", 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://", new Offlinemessagerequest.provider ()); Offline Message indicatorpm.addextensionprovider ("Offline", "Http://", 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://", new Sharedgroupsinfo.provider ()); jep-33:extended Stanza AddressiNgpm.addextensionprovider ("Addresses", "", New Multipleaddressesprovider ()); Filetransferpm.addiqprovider ("Si", "", New Streaminitiationprovider ()); Pm.addiqprovider ("Query", "Http://", New Bytestreamsprovider ()); Privacypm.addiqprovider ("Query", "Jabber:iq:privacy", New Privacyprovider ());p m.addiqprovider ("command", "http:/ / ", New Adhoccommanddataprovider ());p M.addextensionprovider (" malformed-action "," http :// ", New Adhoccommanddataprovider.malformedactionerror ());p M.addextensionprovider (" Bad-locale "," Http:// ", New Adhoccommanddataprovider.badlocaleerror ()); Pm.addextensionprovider ("Bad-payload", "Http://", new Adhoccommanddataprovider.badpayloaderror ());p M.addextensionprovider ("Bad-sessionid", " Protocol/commands ", New Adhoccommanddataprovider.badsessioniderror ());p M.addextensionprovider ("session-expired", "Http://", new Adhoccommanddataprovider.sessionexpirederror ());}

In Connection.connect (); Before establishing a connection


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 = ();               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: 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.