2017-03-01 110 views
1

在我的Android應用程序中有谷歌加登錄按鈕。谷歌加登錄在我的應用程序工作正常。我用這個代碼來訪問谷歌加的個人檔案相片谷歌plus個人資料圖片網址沒有得到

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

的URL時,我使用由這種原因,這code.I了錯誤

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

我應該怎麼做才能的個人資料圖片網址谷歌加帳戶?

回答

1

由於錯誤信息中明確指出,要在空對象上調用的方法「的toString()」,你可以改變你的代碼來捕獲空實例

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

,或者確保「getPhotoURL ()」永遠不會返回null

+0

現在錯誤已經謝謝 –

1

看來你帳戶爲空和你想爲什麼你越來越nullpointerexception來訪問空對象這就是價值。所以請嘗試像這樣得到

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

你的答案也是正確的。 –

+0

@ User1278謝謝,請訂閱我的YouTube頻道,以獲取更多關於手機的更新(Android&ios)。 ** HTTPS://www.youtube.com/channel/UCA5HRmlkT7bqbO56EIlT0UQ** –

相關問題