Reputation: 177
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
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
Reputation: 1282
You can try this with firebase.
https://firebase.google.com/docs/auth/android/google-signin
Upvotes: 0
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