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?
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
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();
You can try this with firebase.
https://firebase.google.com/docs/auth/android/google-signin
Related
I'm using GSON to parse JSON from a web service. I don't have any issues with this on my test device or in the simulator, but I'm getting NullPointerException crashes in the Pre-Launch Report testing on the Play Console when I try to access one of the List objects.
I've tried checking the object for null before accessing it, but I'm still seeing the crash in the Pre-Launch Reports.
Here's the Hourly data class which contains the List object that's causing the crash:
data class Hourly(
#SerializedName("data") val data: List<Conditions> = listOf(),
#SerializedName("summary") val summary: String = "" //Partly cloudy in the evening
)
Here's where I'm accessing the object (with a bunch of extra checks to make sure the objects aren't null before accessing them):
if (forecastData == null || forecastData?.currently == null || forecastData?.hourly == null || forecastData?.hourly?.data == null)
return
val hourlyData = forecastData?.hourly?.data ?: return
if (forecastData?.hourly != null && forecastData?.hourly?.data != null && hourlyData.count() > 2) {
val nextHour = hourlyData[1]
pressure = nextHour.pressure
}
One other thing to note is that this code was all working fine for the past year, but when I updated the app to API 28 and Kotlin 1.3.50 this crash started happening.
Update
I tried setting pretty much every object in my data model class to nullable, but I'm still getting the crash. Here's the end of the crash log, in case that is helpful:
FATAL EXCEPTION: main
Process: com.xxx.xxxx, PID: 27844
java.lang.NullPointerException: throw with null exception
at com.xxx.xxxx.model.Hourly.getData(Hourly.java:3)
at com.xxx.xxxx.view.UserInterface.updateCurrently(UserInterface.java:38)
I assume based on this that I am supposed to check for null on hourly.data...
I have no idea why, but turning off minifyEnabled and turning on multidexEnabled in my release build settings fixed this bug. Glad I spent 3 whole days on this.
currently i am integrating Google Drive API into my app. I can get the title and mimetype correctly.
However, getDownloadUrl seem to return null. Not only that, getThumbnailLink also return null. What is the possible cause for this problem?
code
Log.d("check", String.valueOf(file.getTitle()));
Log.d("check", String.valueOf(file.getMimeType()));
Log.d("check", String.valueOf(file.getDownloadUrl()));
result
D/check: explore.jpg
D/check: image/jpeg
D/check: null
Thanks!
Finally i know the answer, it is return null due to incorrect DriveScope.
Previously i use DriveScope.DRIVE_METADATA_READONLY which caused the file only return metadata. If extra information such as getDownloadUrl and getThumbnailLink, change the DriveScope to DriveScope.DRIVE_READONLY.
More information about DriveScope is available here
https://developers.google.com/drive/v2/web/scopes
I have an application that send me user_email = null when it shouldn't. I don't understant it, and can't reproduce it in local. I would like to use acra reporting to report system state when user_email = null.
I know how to write custom variable:
ACRA.getErrorReporter().putCustomData("myVariable", myVariable);
but I don't know how to generate report if var is null, even if the system doesn't crash ( in my case my null variable does not crash the system)
if ( user_email == null) {
ACRA.getErrorReporter().handleSilentException(null);
}
See https://github.com/ACRA/acra/wiki/AdvancedUsage#wiki-Sending_reports_for_caught_exceptions
I have an Android application with GAE server. I tried to authenticate the user as described on developers.google.com, I added the user parameter to the endpoint methods etc. I get a User which is not null, but this method getUserId() returns null. It is similar to this, rather old problem:
Function User.getUserId() in Cloud endpoint api returns null for a user object that is not null
But I still don't know how to work around it. How do you handle this error? Have you ever encountered it?
In android client here's what I did (its simplified) :
credentials = GoogleAccountCredential.usingAudience(getApplicationContext(), "server:client_id:" + WEB_CLIENT_ID);
credentials.setSelectedAccountName(accountName);
WarriorEntityEndpoint.Builder endpointBuilder = new WarriorEntityEndpoint.Builder(AndroidHttp.newCompatibleTransport(), new GsonFactory(), credentials);
warriorEntityEndpoint = endpointBuilder.build();
new AsyncTask<Void, Void, Void>() {
#Override
protected Void doInBackground(Void... params) {
// TODO Auto-generated method stub
try {
warriorEntityEndpoint.getWarrior().execute();
} catch (Exception e) {
}
return null;
}
}.execute();
And on GAE:
#Api(name = "warriorEntityEndpoint", namespace = #ApiNamespace(ownerDomain = "szpyt.com", ownerName = "szpyt.com", packagePath = "mmorpg.monsters"),
version = "version1",
scopes = {"https://www.googleapis.com/auth/userinfo.email", "https://www.googleapis.com/auth/userinfo.profile"},
clientIds = {Constants.ANDROID_CLIENT_ID, Constants.WEB_CLIENT_ID},
audiences = {Constants.ANDROID_AUDIENCE})
public class WarriorEntityEndpoint {
private static final Logger log = Logger.getLogger(WarriorEntityEndpoint.class.getName());
#ApiMethod(name = "getWarrior")
public WarriorEntity getWarrior(User user) throws OAuthRequestException, IOException {
log.log(Level.SEVERE, "this gives correct email: " + user.getEmail());
log.log(Level.SEVERE, "this is null: " + user.getUserId());
I have also another very important question: is this user authenticated, if getMail() gives me correct account, but getUserId() gives null? I read that user object should be null if it was not authenticated but I am not sure any more...
I'm using App engine SDK 1.8.7. I'm testing on a real device and backend deployed to GAE.
I asked the same question a while ago and got an answer. See link:
Function User.getUserId() in Cloud endpoint api returns null for a user object that is not null
The cause is a bug on appengine.
I guess there is no good solution for it right now. I store e-mail as a normal property and remove it from default fetch group, I use long as a primary key (generated by AppEngine) and I query the entity by the e-mail property. I don't like my solution, I'll accept ( and implement :) ) a better one if anyone can provide.
This is a known issue which has been filed with google, I've attached the issue link below.
There are two workarounds (1) save the user and read back from the store, if it refers to a valid account the user id will be populated (this sucks because you pay the saving / loading / deletion cost for each API access that is authenticated even if it is tiny, and obviously some performance cost) and (2) you could use the google+ ID but that is NOT the same as the user id.
This is extremely frustrating and there is currently no ETA as they are working on some fundamental issues with the auth design as far as I understand.
Please, vote for that issue by starring it. You can find all the information here
https://code.google.com/p/googleappengine/issues/detail?can=2&start=0&num=100&q=&colspec=ID%20Type%20Component%20Status%20Stars%20Summary%20Language%20Priority%20Owner%20Log&groupby=&sort=&id=8848
And here is the current formally approved workaround [(1) above], which you can also find in the link above, but for ease it's here: How can I determine a user_id based on an email address in App Engine?
For workaround (2) mentioned above, you can look at the first link, and go to post #39.
I am working on in app billing of android..i follow tutorial of android and currently i am testing for test app.(android.test.purchased)
I create app on google console
I sign apk and upload it to google console than i copy public key and paste it into my code and sign apk again and install it on phone than i tried to buy test purchased id It display me purchased successful but in my Log value i display the purchaseddata and datasignature and i got datasignature NULL (empty)
The fun part is in handleActivityResult method there is one if condition which checks weather datasignature or purchaseddata is Null or not and in my code it does not execute if skips it ? how it is possible?
Here i pur log but in my logcat i cannot see "In BUG Null value"
if (purchaseData == null || dataSignature == null) {
logError("BUG: either purchaseData or dataSignature is null.");
Log.e("Inapp", "In BUG Null value");
logDebug("Extras: " + data.getExtras().toString());
result = new IabResult(IABHELPER_UNKNOWN_ERROR, "IAB returned null purchaseData or dataSignature");
if (mPurchaseListener != null) mPurchaseListener.onIabPurchaseFinished(result, null);
return true;
}
I had this problem myself. After a while I found what I did wrong. I was calling the wrong method on the IABHelper.
If you call mHelper.launchPurchaseFlow(...) with an SKU that is registered as a subscription on Google Developer Console it will result in the error: IAB returned null purchaseData or dataSignature (response -1008:Unknown error).
If you have a SKU that is registered as an subscription you have to use the method: mHelper.launchSubscriptionPurchaseFlow(...) instead.
Hope this helps.