1
facebookでログインしている間、このエラーが何度も繰り返されています。私は理解できません。親切に助けてください。java.lang.NullPointerException facebookでログインしてください。
public class LoginActivity extends AppCompatActivity {
private CallbackManager callbackManager;
private AccessTokenTracker accessTokenTracker;
private ProfileTracker profileTracker;
//Facebook login button
private FacebookCallback<LoginResult> callback = new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
Profile profile = Profile.getCurrentProfile();
nextActivity(profile);
}
@Override
public void onCancel() { }
@Override
public void onError(FacebookException e) { }
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getApplicationContext());
callbackManager = CallbackManager.Factory.create();
accessTokenTracker = new AccessTokenTracker() {
@Override
protected void onCurrentAccessTokenChanged(AccessToken oldAccessToken, AccessToken currentAccessToken) {
}
};
profileTracker = new ProfileTracker() {
@Override
protected void onCurrentProfileChanged(Profile oldProfile, Profile newProfile) {
nextActivity(newProfile);
}
};
accessTokenTracker.startTracking();
profileTracker.startTracking();
LoginButton loginButton = (LoginButton)findViewById(R.id.login_button);
callback = new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
AccessToken accessToken = loginResult.getAccessToken();
Profile profile = Profile.getCurrentProfile();
nextActivity(profile);
Toast.makeText(getApplicationContext(), "Logging in...", Toast.LENGTH_SHORT).show(); }
@Override
public void onCancel() {
}
@Override
public void onError(FacebookException e) {
}
};
loginButton.setReadPermissions("user_friends");
loginButton.registerCallback(callbackManager, callback);
}
@Override
protected void onResume() {
super.onResume();
//Facebook login
Profile profile = Profile.getCurrentProfile();
nextActivity(profile);
}
@Override
protected void onPause() {
super.onPause();
}
protected void onStop() {
super.onStop();
//Facebook login
accessTokenTracker.stopTracking();
profileTracker.stopTracking();
}
@Override
protected void onActivityResult(int requestCode, int responseCode, Intent intent) {
super.onActivityResult(requestCode, responseCode, intent);
//Facebook login
callbackManager.onActivityResult(requestCode, responseCode, intent);
}
private void nextActivity(Profile profile){
if(profile != null){
Intent main = new Intent(LoginActivity.this, MainActivity.class);
main.putExtra("name", profile.getFirstName());
main.putExtra("surname", profile.getLastName());
main.putExtra("imageUrl", profile.getProfilePictureUri(200,200).toString());
startActivity(main);
}
}
}
エラーは次のとおりです:
08-06 21:58:45.079 16282-16282/com.example.mabdullahali.trenditch E/AndroidRuntime: FATAL EXCEPTION: main
08-06 21:58:45.079 16282-16282/com.example.mabdullahali.trenditch E/AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mabdullahali.trenditch/com.example.mabdullahali.trenditch.LoginActivity}: java.lang.NullPointerException
08-06 21:58:45.079 16282-16282/com.example.mabdullahali.trenditch E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2295)
08-06 21:58:45.079 16282-16282/com.example.mabdullahali.trenditch E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
08-06 21:58:45.079 16282-16282/com.example.mabdullahali.trenditch E/AndroidRuntime: at android.app.ActivityThread.access$700(ActivityThread.java:159)
08-06 21:58:45.079 16282-16282/com.example.mabdullahali.trenditch E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
08-06 21:58:45.079 16282-16282/com.example.mabdullahali.trenditch E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:99)
08-06 21:58:45.079 16282-16282/com.example.mabdullahali.trenditch E/AndroidRuntime: at android.os.Looper.loop(Looper.java:176)
08-06 21:58:45.079 16282-16282/com.example.mabdullahali.trenditch E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5419)
08-06 21:58:45.079 16282-16282/com.example.mabdullahali.trenditch E/AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method)
08-06 21:58:45.079 16282-16282/com.example.mabdullahali.trenditch E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:525)
08-06 21:58:45.079 16282-16282/com.example.mabdullahali.trenditch E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
08-06 21:58:45.079 16282-16282/com.example.mabdullahali.trenditch E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
08-06 21:58:45.079 16282-16282/com.example.mabdullahali.trenditch E/AndroidRuntime: at dalvik.system.NativeStart.main(Native Method)
08-06 21:58:45.079 16282-16282/com.example.mabdullahali.trenditch E/AndroidRuntime: Caused by: java.lang.NullPointerException
08-06 21:58:45.079 16282-16282/com.example.mabdullahali.trenditch E/AndroidRuntime: at com.example.mabdullahali.trenditch.LoginActivity.onCreate(LoginActivity.java:79)
08-06 21:58:45.079 16282-16282/com.example.mabdullahali.trenditch E/AndroidRuntime: at android.app.Activity.performCreate(Activity.java:5372)
08-06 21:58:45.079 16282-16282/com.example.mabdullahali.trenditch E/AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
08-06 21:58:45.079 16282-16282/com.example.mabdullahali.trenditch E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2257)
08-06 21:58:45.079 16282-16282/com.example.mabdullahali.trenditch E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
08-06 21:58:45.079 16282-16282/com.example.mabdullahali.trenditch E/AndroidRuntime: at android.app.ActivityThread.access$700(ActivityThread.java:159)
08-06 21:58:45.079 16282-16282/com.example.mabdullahali.trenditch E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
08-06 21:58:45.079 16282-16282/com.example.mabdullahali.trenditch E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:99)
08-06 21:58:45.079 16282-16282/com.example.mabdullahali.trenditch E/AndroidRuntime: at android.os.Looper.loop(Looper.java:176)
08-06 21:58:45.079 16282-16282/com.example.mabdullahali.trenditch E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5419)
08-06 21:58:45.079 16282-16282/com.example.mabdullahali.trenditch E/AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method)
08-06 21:58:45.079 16282-16282/com.example.mabdullahali.trenditch E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:525)
08-06 21:58:45.079 16282-16282/com.example.mabdullahali.trenditch E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
08-06 21:58:45.079 16282-16282/com.example.mabdullahali.trenditch E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
08-06 21:58:45.079 16282-16282/com.example.mabdullahali.trenditch E/AndroidRuntime: at dalvik.system.NativeStart.main(Native Method)
これが私のマニフェストコード –
'<活動のアンドロイド:名= "LoginActivity。">である <意図-フィルタ> <アクションアンドロイド:名= "android.intent.action.MAIN"/> <カテゴリアンドロイド:名= "android.intent.category.LAUNCHER" /> インテントフィルタ> アプリケーション> ' –