由:java.lang.NullPointerException:尝试调用虚拟方法'java.lang.String com.facebook.Profile.getFirstName()'



我正在尝试使用Facebook API获取有关Android验证的一些数据。我可以登录我的脸书帐户。这是我设置的从Facebook帐户获取数据的权限

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

使用上述权限 我正在尝试获取配置文件名称和其他数据,我收到以下代码片段的空指针异常

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());

拜托,我使用的方法有什么问题。

应用程序尝试使用 具有空值 的对象引用。

getCurrentProfile((

当前登录到应用程序的配置文件的 getter。

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("---------------------");
}

相关内容

最新更新