android - How to solve error while implementing Sign in with Google Plus and Facebook in an activity? -


here, i'm integrating sign in facebook , g+ in project working fine if integrate each in individual activities if integrate both of them in same activity start getting error in code of g+. more i'm going paste code , error. loginactivity i'm integrating both of them is

public class loginactivity extends activity implements onclicklistener,     connectioncallbacks, onconnectionfailedlistener { // facebook app id private static string app_id = "xxxxxxxxxxxxxxx"; // replace app                                                     // id linearlayout ll; // strings of facebook string fb_muserid = "", fb_musertoken = "", fb_musername = "",         fb_museremail = "", fb_verified_value = "", fb_task_message; boolean fb_verified, google_verified; // instance of facebook class private facebook facebook = new facebook(app_id); @suppresswarnings("unused") private asyncfacebookrunner masyncrunner; string filename = "androidsso_data"; private sharedpreferences mprefs; edittext edittext_username, edittext_password; button btn_login, btn_register; textview text_univesity, errormsg, tv_forget_password; linearlayout ll_google, ll_fb; static string username, password, name, twilio_id = "",         name_candidate = "", phone_no = "", email_candidate = "",         country = "", mobile_verification = "", fb_id = ""; imageview im; arraylist<hashmap<string, string>> list = new arraylist<hashmap<string, string>>(); int id, mode = 0, fb_clicked = 0, google_clicked = 0; static int user_ids; string imei_number; gpstracker gps; static double latitude = 0.00, longitude = 0.00; context context;  private static final int rc_sign_in = 0; // logcat tag private static final string tag = "loginactivity"; // profile pic image size in pixels // private static final int profile_pic_size = 400; // google client interact google api private googleapiclient mgoogleapiclient; /**  * flag indicating pendingintent in progress , prevents  * starting further intents.  */ private boolean mintentinprogress; private boolean msigninclicked; private connectionresult mconnectionresult; // strings of google plus string google_email="", google_id="", google_name="", google_verified_value="";  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_login);     strictmode.threadpolicy policy = new strictmode.threadpolicy.builder()             .permitall().build();     strictmode.setthreadpolicy(policy);     telephonymanager telephonymanager = (telephonymanager) getsystemservice(context.telephony_service);     imei_number = telephonymanager.getdeviceid();     im = (imageview) findviewbyid(r.id.header);     masyncrunner = new asyncfacebookrunner(facebook);       if (mode == 3) {         if (login_details.contains("name")) {             name = login_details.getstring("name", "");             intercom.client().registeridentifieduser(                     new registration().withuserid(name));         } else {             intercom.client().registeridentifieduser(                     new registration().withuserid("123456"));         }         // we're logged in, can register user intercom         // carry on normal         intent mode = new intent(loginactivity.this, menuitems.class);         startactivity(mode);         finish();     } else {         edittext_password = (edittext) findviewbyid(r.id.et_login_password);         btn_login = (button) findviewbyid(r.id.btn_login);         btn_register = (button) findviewbyid(r.id.btn_login_register);         ll_fb = (linearlayout) findviewbyid(r.id.login_fb);         ll_google = (linearlayout) findviewbyid(r.id.login_google);         tv_forget_password = (textview) findviewbyid(r.id.tv_login_forget_password);         btn_login.setonclicklistener(this);         btn_register.setonclicklistener(this);         ll_fb.setonclicklistener(this);         ll_google.setonclicklistener(this);         tv_forget_password.setonclicklistener(this);          // initializing google plus api client         mgoogleapiclient = new googleapiclient.builder(this)                 .addconnectioncallbacks(this)                 .addonconnectionfailedlistener(this).addapi(plus.api)                 .addscope(plus.scope_plus_profile).build();     }  }  @override public void onclick(view v) {     switch (v.getid()) {      case r.id.btn_login:    // direct login process         break;     case r.id.btn_login_register:         // direct register process         finish();         break;     case r.id.login_fb:         fb_clicked++;         logintofacebook();         getprofileinformation();         if (!fb_museremail.equals("")) {             if (fb_verified == true) {                 fb_verified_value = "1";             } else {                 fb_verified_value = "0";             }             new facebookasyntask().execute();         }         break;     case r.id.login_google:         google_clicked++;         signinwithgplus();     //  getgoogleprofileinformation();         if (!google_email.equals("")) {             if (google_verified == true) {                 google_verified_value = "1";             } else {                 google_verified_value = "0";             }             new googleasyntask().execute();         }         break;     case r.id.tv_login_forget_password:         break;      } }  @override protected void onresume() {     super.onresume(); }  protected void onstart() {     super.onstart();     mgoogleapiclient.connect(); }  protected void onstop() {     super.onstop();     if (mgoogleapiclient.isconnected()) {         mgoogleapiclient.disconnect();     } }  /** login facebook */ public void logintofacebook() {     mprefs = getpreferences(mode_private);     string access_token = mprefs.getstring("access_token", null);     long expires = mprefs.getlong("access_expires", 0);      if (access_token != null) {         facebook.setaccesstoken(access_token);         log.d("fb sessions", "" + facebook.issessionvalid());         toast.maketext(loginactivity.this, "first case", toast.length_short)                 .show();         getprofileinformation();     }      if (expires != 0) {         facebook.setaccessexpires(expires);     }      if (!facebook.issessionvalid()) {         facebook.authorize(this,                 new string[] { "email", "publish_actions" },                 new dialoglistener() {                      @override                     public void oncancel() {                         // function handle cancel event                     }                      @override                     public void oncomplete(bundle values) {                         // function handle complete event                         // edit preferences , update facebook acess_token                         sharedpreferences.editor editor = mprefs.edit();                         editor.putstring("access_token",                                 facebook.getaccesstoken());                         editor.putlong("access_expires",                                 facebook.getaccessexpires());                         editor.commit();                         toast.maketext(loginactivity.this, "second case",                                 toast.length_short).show();                         getprofileinformation();                          // making login button invisible                      }                      public void onerror(dialogerror error) {                         // function handle error                     }                      public void onfacebookerror(facebookerror fberror) {                         // function handle facebook errors                     }                  });     } }  @override public void onactivityresult(int requestcode, int resultcode, intent data) {     super.onactivityresult(requestcode, resultcode, data);     if (fb_clicked != 0) {         facebook.authorizecallback(requestcode, resultcode, data);         fb_clicked = 0;     }     else if (google_clicked != 0) {          if (requestcode == rc_sign_in) {             if (resultcode != result_ok) {                 msigninclicked = false;             }              mintentinprogress = false;              if (!mgoogleapiclient.isconnecting()) {                 mgoogleapiclient.connect();             }         }         google_clicked = 0;     } }  /**  * profile information making request facebook graph api  * */ public void getprofileinformation() {     try {          jsonobject profile = util.parsejson(facebook.request("me"));         log.e("profile", "" + profile);         fb_muserid = profile.getstring("id");         fb_verified = profile.getboolean("verified");         fb_musertoken = facebook.getaccesstoken();         fb_musername = profile.getstring("name");         fb_museremail = profile.getstring("email");          runonuithread(new runnable() {              public void run() {                  log.e("facebook_profile", "" + fb_muserid + "\n"                         + fb_musertoken + "\n" + fb_musername + "\n"                         + fb_museremail);             }         });      } catch (facebookerror e) {          e.printstacktrace();     } catch (malformedurlexception e) {          e.printstacktrace();     } catch (jsonexception e) {          e.printstacktrace();     } catch (ioexception e) {          e.printstacktrace();     } }  /** asynctask of direct login */   class facebookasyntask extends asynctask<void, void, void> {  }  /** google's code starts */ /**  * sign-in google  * */ private void signinwithgplus() {     if (!mgoogleapiclient.isconnecting()) {         msigninclicked = true;         resolvesigninerror();     } }  /**  * method resolve signin errors  * */ private void resolvesigninerror() {     if (mconnectionresult.hasresolution()) {         try {             mintentinprogress = true;             mconnectionresult.startresolutionforresult(this, rc_sign_in);         } catch (sendintentexception e) {             mintentinprogress = false;             mgoogleapiclient.connect();         }     } }  @override public void onconnectionfailed(connectionresult result) {     if (!result.hasresolution()) {         googleplayservicesutil.geterrordialog(result.geterrorcode(), this,                 0).show();         return;     }      if (!mintentinprogress) {         // store connectionresult later usage         mconnectionresult = result;          if (msigninclicked) {             // user has clicked 'sign-in' attempt             // resolve             // errors until user signed in, or cancel.             resolvesigninerror();         }     }  }  @override public void onconnected(bundle arg0) {     msigninclicked = false;     toast.maketext(this, "user connected!", toast.length_long).show();      // user's information     getgoogleprofileinformation();      // update ui after signin     // updateui(true);  }  @override public void onconnectionsuspended(int arg0) {     mgoogleapiclient.connect();     // updateui(false); }  /**  * fetching user's information name, email, profile pic  * */ private void getgoogleprofileinformation() {     try {         if (plus.peopleapi.getcurrentperson(mgoogleapiclient) != null) {             person currentperson = plus.peopleapi                     .getcurrentperson(mgoogleapiclient);             google_name = currentperson.getdisplayname();             google_id = currentperson.getid();             google_verified = currentperson.isverified();             string personphotourl = currentperson.getimage().geturl();             string persongoogleplusprofile = currentperson.geturl();             google_email = plus.accountapi.getaccountname(mgoogleapiclient);              log.e(tag, "name: " + google_name + ", plusprofile: "                     + persongoogleplusprofile + ", email: " + google_email                     + ", image: " + personphotourl);              // default profile url gives 50x50 px image             // can replace value whatever dimension want             // replacing sz=x          } else {             toast.maketext(getapplicationcontext(),                     "person information null", toast.length_long).show();         }     } catch (exception e) {         e.printstacktrace();     } }  class googleasyntask extends asynctask<void, void, void> { } 

here, problem in method of nullpointerexception.

private void resolvesigninerror() {     if (mconnectionresult.hasresolution()) {         try {             mintentinprogress = true;             mconnectionresult.startresolutionforresult(this, rc_sign_in);         } catch (sendintentexception e) {             mintentinprogress = false;             mgoogleapiclient.connect();         }     } } 

my logcat shows this:

07-08 10:42:40.844: e/androidruntime(11981): fatal exception: main 07-08 10:42:40.844: e/androidruntime(11981): java.lang.nullpointerexception 07-08 10:42:40.844: e/androidruntime(11981):    @ com.u18.enroll.loginactivity.resolvesigninerror(loginactivity.java:752) 07-08 10:42:40.844: e/androidruntime(11981):    @ com.u18.enroll.loginactivity.signinwithgplus(loginactivity.java:744) 07-08 10:42:40.844: e/androidruntime(11981):    @ com.u18.enroll.loginactivity.onclick(loginactivity.java:236) 07-08 10:42:40.844: e/androidruntime(11981):    @ android.view.view.performclick(view.java:4209) 07-08 10:42:40.844: e/androidruntime(11981):    @ android.view.view$performclick.run(view.java:17431) 07-08 10:42:40.844: e/androidruntime(11981):    @ android.os.handler.handlecallback(handler.java:725) 07-08 10:42:40.844: e/androidruntime(11981):    @ android.os.handler.dispatchmessage(handler.java:92) 07-08 10:42:40.844: e/androidruntime(11981):    @ android.os.looper.loop(looper.java:153) 07-08 10:42:40.844: e/androidruntime(11981):    @ android.app.activitythread.main(activitythread.java:5297) 07-08 10:42:40.844: e/androidruntime(11981):    @ java.lang.reflect.method.invokenative(native method) 07-08 10:42:40.844: e/androidruntime(11981):    @ java.lang.reflect.method.invoke(method.java:511) 07-08 10:42:40.844: e/androidruntime(11981):    @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:833) 07-08 10:42:40.844: e/androidruntime(11981):    @ com.android.internal.os.zygoteinit.main(zygoteinit.java:600) 07-08 10:42:40.844: e/androidruntime(11981):    @ dalvik.system.nativestart.main(native method) 07-08 10:42:43.446: e/nativecrypto(11981): ssl=0x5f72edf0 cert_verify_callback x509_store_ctx=0x5eaafaa0 arg=0x0 07-08 10:42:43.447: e/nativecrypto(11981): ssl=0x5f72edf0 cert_verify_callback calling verifycertificatechain authmethod=ecdhe_rsa 

it shows error in 236 line i'm calling signinwithgplus() method

if has solve problem me , give me right way.

thanks.

finally, solved problem of sree 1 condition is

if (mgoogleapiclient.isconnected()) {         getprofileinformation();     } else {         signinwithgplus();         getprofileinformation();     }  } 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -