User 1278
User 1278

Reputation: 177

Google plus profile pic url is not getting

In my android app there is google plus login button.Google plus login works fine in my app. I use this code to access url of google plus profile pic

String profileurl=Account.getPhotoUrl().toString();

When I use this code.I got errors caused by this reason

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.net.Uri.toString()' on a null object reference

What should I do to get profile picture url of google plus account?

Upvotes: 1

Views: 556

Answers (3)

Dharmbir Singh
Dharmbir Singh

Reputation: 17535

It seems your Account is null and you are trying to access value on null object thats why you are getting null pointer exception. So please try to get like this

GoogleSignInResult result;// its your google result
GoogleSignInAccount acct = result.getSignInAccount();// here your Account value is null

String profileURL = "";
if (acct != null)
   profileURL = acct.getPhotoUrl().toString();

Upvotes: 1

Sushant
Sushant

Reputation: 1282

You can try this with firebase.

https://firebase.google.com/docs/auth/android/google-signin

Upvotes: 0

Rafael Francisco
Rafael Francisco

Reputation: 310

As the error message clearly states, you are invoking the method "toString()" on a null object, you can either change your code to catch null instances

if (Account.getPhotoUrl() != null){
    String profileurl=Account.getPhotoUrl().toString();
}

or make sure that "getPhotoURL()" never returns null

Upvotes: 1

Related Questions