2017-07-19 4 views
1

Ich versuche, einige Daten auf meiner Android-Validierung mit Facebook API zu holen. Ich kann mich in meinen Facebook-Account einloggen. Dies ist die Erlaubnis, ich gesetzt haben Daten von Facebook-Account holenVerursacht von: java.lang.NullPointerException: Versuch, virtuelle Methode aufzurufen 'java.lang.String com.facebook.Profile.getFirstName()'

loginButton.setReadPermissions(Arrays.asList("public_profile", "email", "user_birthday", "user_friends")); 

die obigen Berechtigungen mit I I Profilnamen und andere Daten zu holen versuche ich eine Null-Zeiger-Ausnahme mit dem folgenden Code-Schnipsel bekommen

public void getFacebookData(AccessToken accessToken, Profile profile) { 
     System.out.println("---------------------"); 
     System.out.println("--Facebook Login Successful!"); 
     System.out.println("--Logged in user Details : "); 
     System.out.println("---------------------"); 
     System.out.println("--User ID : " + accessToken.getUserId()); 
     System.out.println("--Authentication Token : " + accessToken.getToken()); 
     System.out.println("---------------------"); 
     System.out.println("--First Name : " + profile.getFirstName()); 
     System.out.println("--Last Name : " + profile.getLastName()); 
     System.out.println("--URL Perfil: " + profile.getLinkUri()); 
     System.out.println("--URL Imagem: " + profile.getProfilePictureUri(500, 500)); 
     System.out.println("---------------------"); 
     System.out.println("--ID : " + profile.getId()); 
     System.out.println("--Name : " + profile.getName()); 
     System.out.println("---------------------"); 

     TextView profile_name = (TextView)findViewById(R.id.profile); 
     profile_name.setText(profile.getName()); 

Bitte, was ist falsch mit dem Ansatz, den ich verwende.

+0

Offensichtlich ** Profil ** ist ** ** null. – GhostCat

Antwort

0

NullPointerException wird ausgelöst, wenn eine Anwendung versucht, eine Objektreferenz mit dem Nullwert zu verwenden.

getCurrentProfile()

Getter für das Profil, das derzeit in der Anwendung angemeldet ist.

public void getFacebookData(AccessToken accessToken, Profile profile) { 
    System.out.println("---------------------"); 
    profile = Profile.getCurrentProfile(); // Add this 
    if (profile != null) 
    { 
    System.out.println("--First Name : " + profile.getFirstName()); 
    System.out.println("--Last Name : " + profile.getLastName()); 
    System.out.println("--URL Perfil: " + profile.getLinkUri()); 
    System.out.println("--URL Imagem: " + profile.getProfilePictureUri(500, 500)); 
    System.out.println("---------------------"); 
    System.out.println("--ID : " + profile.getId()); 
    System.out.println("--Name : " + profile.getName()); 
    System.out.println("---------------------"); 

    } 
+0

Profil gibt immer noch Null zurück, hat dies mit dem Konto zu tun, das ich verwende – blend

+0

@blend kann sein! DEBUG bitte –

Verwandte Themen