login - Log in Using Google Plus Android ERROR -


i trying log in using google + having problem.

heres import code:

package info.androidhive.gpluslogin;  import java.io.inputstream;  import android.app.activity; import android.content.intent; import android.content.intentsender.sendintentexception; import android.graphics.bitmap; import android.graphics.bitmapfactory; import android.os.asynctask; import android.os.bundle; import android.util.log; import android.view.menu; import android.view.view; import android.view.view.onclicklistener; import android.widget.button; import android.widget.imageview; import android.widget.linearlayout; import android.widget.textview; import android.widget.toast;  import com.google.android.gms.common.connectionresult; import com.google.android.gms.common.googleplayservicesutil; import com.google.android.gms.common.signinbutton; import com.google.android.gms.common.api.googleapiclient; import com.google.android.gms.common.api.googleapiclient.connectioncallbacks; import com.google.android.gms.common.api.googleapiclient.onconnectionfailedlistener; import com.google.android.gms.common.api.resultcallback; import com.google.android.gms.common.api.status; import com.google.android.gms.plus.plus; import com.google.android.gms.plus.model.people.person; 

heres main activity code:

    public class mainactivity extends activity implements onclicklistener,     connectioncallbacks, onconnectionfailedlistener {  private static final int rc_sign_in = 0; // logcat tag private static final string tag = "mainactivity";  // 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;  private signinbutton btnsignin; private button btnsignout, btnrevokeaccess; private imageview imgprofilepic; private textview txtname, txtemail; private linearlayout llprofilelayout;  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);      btnsignin = (signinbutton) findviewbyid(r.id.btn_sign_in);     btnsignout = (button) findviewbyid(r.id.btn_sign_out);     btnrevokeaccess = (button) findviewbyid(r.id.btn_revoke_access);     imgprofilepic = (imageview) findviewbyid(r.id.imgprofilepic);     txtname = (textview) findviewbyid(r.id.txtname);     txtemail = (textview) findviewbyid(r.id.txtemail);     llprofilelayout = (linearlayout) findviewbyid(r.id.llprofile);      // button click listeners     btnsignin.setonclicklistener(this);     btnsignout.setonclicklistener(this);     btnrevokeaccess.setonclicklistener(this);      mgoogleapiclient = new googleapiclient.builder(this)             .addconnectioncallbacks(this)             .addonconnectionfailedlistener(this).addapi(plus.api, null)             .addscope(plus.scope_plus_login).build(); }  protected void onstart() {     super.onstart();     mgoogleapiclient.connect(); }  protected void onstop() {     super.onstop();     if (mgoogleapiclient.isconnected()) {         mgoogleapiclient.disconnect();     } }  /**  * 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 protected void onactivityresult(int requestcode, int responsecode,         intent intent) {     if (requestcode == rc_sign_in) {         if (responsecode != result_ok) {             msigninclicked = false;         }          mintentinprogress = false;          if (!mgoogleapiclient.isconnecting()) {             mgoogleapiclient.connect();         }     } }  @override public void onconnected(bundle arg0) {     msigninclicked = false;     toast.maketext(this, "user connected!", toast.length_long).show();      // user's information     getprofileinformation();      // update ui after signin     updateui(true);  }  /**  * updating ui, showing/hiding buttons , profile layout  * */ private void updateui(boolean issignedin) {     if (issignedin) {         btnsignin.setvisibility(view.gone);         btnsignout.setvisibility(view.visible);         btnrevokeaccess.setvisibility(view.visible);         llprofilelayout.setvisibility(view.visible);     } else {         btnsignin.setvisibility(view.visible);         btnsignout.setvisibility(view.gone);         btnrevokeaccess.setvisibility(view.gone);         llprofilelayout.setvisibility(view.gone);     } }  /**  * fetching user's information name, email, profile pic  * */ private void getprofileinformation() {     try {         if (plus.peopleapi.getcurrentperson(mgoogleapiclient) != null) {             person currentperson = plus.peopleapi                     .getcurrentperson(mgoogleapiclient);             string personname = currentperson.getdisplayname();             string personphotourl = currentperson.getimage().geturl();             string persongoogleplusprofile = currentperson.geturl();             string email = plus.accountapi.getaccountname(mgoogleapiclient);              log.e(tag, "name: " + personname + ", plusprofile: "                     + persongoogleplusprofile + ", email: " + email                     + ", image: " + personphotourl);              txtname.settext(personname);             txtemail.settext(email);              // default profile url gives 50x50 px image             // can replace value whatever dimension want             // replacing sz=x             personphotourl = personphotourl.substring(0,                     personphotourl.length() - 2)                     + profile_pic_size;              new loadprofileimage(imgprofilepic).execute(personphotourl);          } else {             toast.maketext(getapplicationcontext(),                     "person information null", toast.length_long).show();         }     } catch (exception e) {         e.printstacktrace();     } }  @override public void onconnectionsuspended(int arg0) {     mgoogleapiclient.connect();     updateui(false); }  @override public boolean oncreateoptionsmenu(menu menu) {     // inflate menu; adds items action bar if present.     getmenuinflater().inflate(r.menu.main, menu);     return true; }  /**  * button on click listener  * */ @override public void onclick(view v) {     switch (v.getid()) {     case r.id.btn_sign_in:         // signin button clicked         signinwithgplus();         break;     case r.id.btn_sign_out:         // signout button clicked         signoutfromgplus();         break;     case r.id.btn_revoke_access:         // revoke access button clicked         revokegplusaccess();         break;     } }  /**  * sign-in google  * */ private void signinwithgplus() {     if (!mgoogleapiclient.isconnecting()) {         msigninclicked = true;         resolvesigninerror();     } }  /**  * sign-out google  * */ private void signoutfromgplus() {     if (mgoogleapiclient.isconnected()) {         plus.accountapi.cleardefaultaccount(mgoogleapiclient);         mgoogleapiclient.disconnect();         mgoogleapiclient.connect();         updateui(false);     } }  /**  * revoking access google  * */ private void revokegplusaccess() {     if (mgoogleapiclient.isconnected()) {         plus.accountapi.cleardefaultaccount(mgoogleapiclient);         plus.accountapi.revokeaccessanddisconnect(mgoogleapiclient)                 .setresultcallback(new resultcallback<status>() {                     @override                     public void onresult(status arg0) {                         log.e(tag, "user access revoked!");                         mgoogleapiclient.connect();                         updateui(false);                     }                  });     } }  /**  * background async task load user profile picture url  * */ private class loadprofileimage extends asynctask<string, void, bitmap> {     imageview bmimage;      public loadprofileimage(imageview bmimage) {         this.bmimage = bmimage;     }      protected bitmap doinbackground(string... urls) {         string urldisplay = urls[0];         bitmap micon11 = null;         try {             inputstream in = new java.net.url(urldisplay).openstream();             micon11 = bitmapfactory.decodestream(in);         } catch (exception e) {             log.e("error", e.getmessage());             e.printstacktrace();         }         return micon11;     }      protected void onpostexecute(bitmap result) {         bmimage.setimagebitmap(result);     } }  } 

manifest:

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="info.androidhive.gpluslogin" android:versioncode="1" android:versionname="1.0" >  <uses-sdk     android:minsdkversion="9"     android:targetsdkversion="18" />  <uses-permission android:name="android.permission.internet" /> <uses-permission android:name="android.permission.get_accounts" /> <uses-permission android:name="android.permission.use_credentials" />  <application     android:allowbackup="true"     android:icon="@drawable/ic_launcher"     android:label="@string/app_name"     android:theme="@style/apptheme" >     <meta-data         android:name="com.google.android.gms.version"         android:value="@integer/google_play_services_version" />      <activity         android:name="info.androidhive.gpluslogin.mainactivity"         android:label="@string/app_name"         android:screenorientation="portrait" >         <intent-filter>             <action android:name="android.intent.action.main" />              <category android:name="android.intent.category.launcher" />         </intent-filter>     </activity> </application>  </manifest> 

my error is:

java.lang.runtimeexception: unable start activity componentinfo{info.androidhive.gpluslogin/info.androidhive.gpluslogin.mainactivity}: java.lang.nullpointerexception: null options not permitted api 

i have started tutorial , got error have no idea error is, have tried googling no answers.

you can download exact app site , try yourself: http://www.androidhive.info/2014/02/android-login-with-google-plus-account-1/

it year ago missing small.

thank reading , help.

remove null, parameter , try ,

        mgoogleapiclient = new googleapiclient.builder(this).addconnectioncallbacks(this)             .addonconnectionfailedlistener(this).addapi(plus.api).addscope(plus.scope_plus_login).build(); 

read here doc


Popular posts from this blog

html/hta mutiple file in audio player -

debugging - Reference - What does this error mean in PHP? -