android - Facebook SDK 4.0.1 Login without login button -


i'm trying log in without using login button. followed facebook tutorial can not work, give me nullpointerexception. manifest:

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"     package="com.example.hema.testfcaebooksdk" >      <uses-permission android:name="android.permission.internet"/>      <application         android:allowbackup="true"         android:icon="@mipmap/ic_launcher"         android:label="@string/app_name"         android:theme="@style/apptheme" >          <meta-data android:name="com.facebook.sdk.applicationid" android:value="@string/facebook_app_id"/>          <activity android:name="com.facebook.facebookactivity"             android:configchanges=                 "keyboard|keyboardhidden|screenlayout|screensize|orientation"             android:theme="@android:style/theme.translucent.notitlebar"             android:label="@string/app_name" />          <provider android:authorities="com.facebook.app.facebookcontentprovider****************"             android:name="com.facebook.facebookcontentprovider"             android:exported="true" />          <activity             android:name=".mainactivity"             android:label="@string/app_name" >             <intent-filter>                 <action android:name="android.intent.action.main" />                  <category android:name="android.intent.category.launcher" />             </intent-filter>         </activity>     </application>  </manifest> 

my activity use login facebook:

public class mainactivity extends actionbaractivity {      callbackmanager callbackmanager;     loginmanager loginmanager;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);          facebooksdk.sdkinitialize(getapplicationcontext());          callbackmanager = callbackmanager.factory.create();          loginmanager = loginmanager.getinstance();          loginmanager.registercallback(callbackmanager,                 new facebookcallback<loginresult>() {                     @override                     public void onsuccess(loginresult loginresult) {                         // app code                         toast.maketext(getapplicationcontext(), loginresult.getaccesstoken().tostring(), toast.length_short).show();                      }                      @override                     public void oncancel() {                         // app code                     }                      @override                     public void onerror(facebookexception exception) {                         // app code                     }                 });          collection<string> permissions = arrays.aslist("public_profile", "user_friends");          loginmanager.loginwithreadpermissions(this, permissions); // null pointer exception here     }       @override     public boolean oncreateoptionsmenu(menu menu) {         // inflate menu; adds items action bar if present.         getmenuinflater().inflate(r.menu.menu_main, menu);         return true;     }      @override     public boolean onoptionsitemselected(menuitem item) {         // handle action bar item clicks here. action bar         // automatically handle clicks on home/up button, long         // specify parent activity in androidmanifest.xml.         int id = item.getitemid();          //noinspection simplifiableifstatement         if (id == r.id.action_settings) {             return true;         }          return super.onoptionsitemselected(item);     }      @override     protected void onactivityresult(int requestcode, int resultcode, intent data) {         super.onactivityresult(requestcode, resultcode, data);         callbackmanager.onactivityresult(requestcode, resultcode, data);     } } 

my log cat:

04-14 20:03:46.840    8075-8075/com.example.hema.testfacebooksdk e/androidruntime﹕ fatal exception: main     process: com.example.hema.testfacebooksdk, pid: 8075     java.lang.runtimeexception: unable start activity componentinfo{com.example.hema.testfacebooksdk/com.example.hema.testfacebooksdk.mainactivity}: java.lang.nullpointerexception             @ android.app.activitythread.performlaunchactivity(activitythread.java:2413)             @ android.app.activitythread.handlelaunchactivity(activitythread.java:2471)             @ android.app.activitythread.access$900(activitythread.java:175)             @ android.app.activitythread$h.handlemessage(activitythread.java:1308)             @ android.os.handler.dispatchmessage(handler.java:102)             @ android.os.looper.loop(looper.java:146)             @ android.app.activitythread.main(activitythread.java:5602)             @ java.lang.reflect.method.invokenative(native method)             @ java.lang.reflect.method.invoke(method.java:515)             @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1283)             @ com.android.internal.os.zygoteinit.main(zygoteinit.java:1099)             @ dalvik.system.nativestart.main(native method)      caused by: java.lang.nullpointerexception             @ com.facebook.login.loginmanager.getlogger(loginmanager.java:391)             @ com.facebook.login.loginmanager.logcompletelogin(loginmanager.java:414)             @ com.facebook.login.loginmanager.startlogin(loginmanager.java:384)             @ com.facebook.login.loginmanager.loginwithreadpermissions(loginmanager.java:262)             @ com.example.hema.testfacebooksdk.mainactivity.oncreate(mainactivity.java:59)             @ android.app.activity.performcreate(activity.java:5451)             @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1093)             @ android.app.activitythread.performlaunchactivity(activitythread.java:2377)             at android.app.activitythread.handlelaunchactivity(activitythread.java:2471)             at android.app.activitythread.access$900(activitythread.java:175)             at android.app.activitythread$h.handlemessage(activitythread.java:1308)             at android.os.handler.dispatchmessage(handler.java:102)             at android.os.looper.loop(looper.java:146)             at android.app.activitythread.main(activitythread.java:5602)             at java.lang.reflect.method.invokenative(native method)             at java.lang.reflect.method.invoke(method.java:515)             at com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1283)             at com.android.internal.os.zygoteinit.main(zygoteinit.java:1099)             at dalvik.system.nativestart.main(native method) 

i tried every thing ended nullpointerexception please me!

ok don't know if had solve problem here how solved it

 list<string> permissionneeds= arrays.aslist("user_photos", "friends_photos", "email", "user_birthday", "user_friends");      super.oncreate(savedinstancestate);     facebooksdk.sdkinitialize(getapplicationcontext());     mcallbackmanager = callbackmanager.factory.create();     loginmanager.getinstance().loginwithreadpermissions(             this,            permissionneeds);     loginmanager.getinstance().registercallback(mcallbackmanager,             new facebookcallback<loginresult>() {                 @override                 public void onsuccess(loginresult loginresults) {                      graphrequest request = graphrequest.newmerequest(                             loginresults.getaccesstoken(),                             new graphrequest.graphjsonobjectcallback() {                                 @override                                 public void oncompleted(                                         jsonobject object,                                         graphresponse response) {                                     // application code                                     log.v("loginactivity", response.tostring());                                 }                             });                     bundle parameters = new bundle();                     parameters.putstring("fields", "id,name,email,gender, birthday");                     request.setparameters(parameters);                     request.executeasync();                  }                 @override                 public void oncancel() {                      log.e("dd","facebook login canceled");                  }                   @override                 public void onerror(facebookexception e) {                        log.e("dd", "facebook login failed error");                  }             }); 

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

order - Notification for user in user account opencart -