When attempting to launch billing for an in-app item, I am getting the following error.
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Intent.getStringExtra(java.lang.String)' on a null object reference
The code is simple. The user selects an item. I then pass that item into querySkuDetailsAsync. I get and see the result. For API reasons, I then call...
SkuDetails skuDetails = new SkuDetails(skuDetails.getOriginalJSON());
BillingFlowParams flowParams = BillingFlowParams.newBuilder().setSkuDetails(skuDetails).build();
BillingResult billingResult = client.launchBillingFlow(activity, flowParams);
And then, most of the time, I get the NPE. Things were working fine. I don't know what change caused this issue.
Note that I did try passing the skuDetails directly, in case JSON was the issue. It didn't work.
The billing library isn't open source, so I am at a loss as to how to solve this issue.
I found a solution. If I call activity.setIntent(new Intent()) before calling "launchBillingFlow", the error goes away. Seems like a bug in the now closed sourced billing library.
Related
So, like the title says I'm trying to retrieve passed arguments from a bundle according to the documentation I'm following by using var args = GameWonFragmentArgs.fromBundle(arguments!!).
But Android Studio suggests using the following code:
var args = GameWonFragmentArgs.fromBundle(requireArguments())
I looked up the Android Documentation for Fragment and found that requireArguments() returns a #NonNull Bundle or an IllegalStateException. Why does Android Studio suggest using it and what's the difference between the two?
Also, I couldn't find relevant documentation about fromBundle().
There is some api changes in androidx.fragment:fragment
requireArguments() --- method which returns a #NonNull Bundle or throws an IllegalStateException.
fromBundle(arguments!!) --- these case App may be crashed because of Null pointer exception. if arguments is null app will be crashed.
As per the UseRequireInsteadOfGet Lint warning:
AndroidX added new "require____()" versions of common "get___()" APIs, such as getContext/getActivity/getArguments/etc. Rather than wrap these in something like requireNotNull(), using these APIs will allow the underlying component to try to tell you why it was null, and thus yield a better error message.
Importantly, the error messages always mention which fragment caused the issue, including the class name of the Fragment and its unique ID. This can be particularly useful when correlating that ID with Fragment's debug logging, thus allowing you to understand when that Fragment was first added or updated.
FirebaseAuth.getCurrentUser() is returning null value. Previously my code worked fine but since couple of days its returning currentUser as null.
Also I've tried my app on another device and in that device everything is working fine with the same code.
mAuth=FirebaseAuth.getInstance();
mCurrentUser=mAuth.getCurrentUser()
mUserDatabase=FirebaseDatabase.getInstance().getReference().child("Users")
.child(mCurrentUser.getUid());
Exception:
Caused by: java.lang.NullPointerException: Attempt to invoke virtual
method 'java.lang.String
com.google.firebase.auth.FirebaseUser.getUid()' on a null object
reference
I have already tried erasing app data and uninstalling and reinstalling my app on my device but nothing worked.
Is there a problem with my device or Firebase?
It looks like the user isn't signed into your app, which causes mCurrentUser.getUid() to throw an exception.
The solution is to only call getUid() is there is a signed-in yser:
mCurrentUser=mAuth.getCurrentUser();
if (mCurrentUser != null) {
mUserDatabase=FirebaseDatabase.getInstance().getReference().child("Users")
.child(mCurrentUser.getUid());
}
Whenever I call getContentResolver().applyBatch(authority,batch), My app crashes on a Asus mobile, while it works fine on other android smartphones.
Logcat
java.lang.NullPointerException: Attempt to get length of null array
at android.content.ContentProvider$Transport.applyBatch(ContentProvider.java:288)
at android.content.ContentProviderClient.applyBatch(ContentProviderClient.java:377)
at android.content.ContentResolver.applyBatch(ContentResolver.java:1244)
How can I solve this problem?
What happens:
You are calling ContentResolver.applyBatch() with a null operations array, this is why you receive a NullPointerException.
This method expects this parameter not to be null, as shown by its signature:
public #NonNull ContentProviderResult[] applyBatch(#NonNull String authority,
#NonNull ArrayList<ContentProviderOperation> operations)
throws RemoteException, OperationApplicationException
You should test the validity of your batch array before calling applyBatch(), and refrain from calling it should batch be null (assuming that having it null means there's no operation to apply).
Why does it work on some cellphones and not on other?
Either because the list of operations to apply depends on the cellphone itself or its configuration (installed apps, Android API, stored data, anything...), which makes it null in the specific case of your Asus ;
or because it works "by accident" on the other cellphones you have tested. This happens sometimes when the code does something wrong but without raising any error due to some permissivity you cannot rely on.
This depends on what your app does.
Tried to implement webrtc audio/video call in my application using Quickblox SDK version 2.2.1. Implemented QBRTCClientCallback interface on an Android Service Class. Able to make audio/video calls, but consistency is the issue. I'm able to make audio/video calls, but consistency is the issue . Getting NullPointerException sometimes when creating session with opponents while making calls.
Following is the code:
QBRTCSession newSessionWithOpponents = QBRTCClient.getInstance().createNewSessionWithOpponents(opponents, qbConferenceType);
I'm getting values for QBRTCClient.getInstance(),opponents, and qbConferenceType.
How can we solve this issue?
Do we have any alternate method to create session rather than createNewSessionWithOpponents?
Is this because of implementing QBRTCClientCallback interface on Android Service Class?
QBRTCClient.getInstance().getActivity() sometimes becomes null and you wont be able to create session in that case since createNewSessionWithOpponents method uses QBRTCClient.getInstance().getActivity()
Try adding below code before creating session
if(QBRTCClient.getInstance().getActivity() == null) {
QBRTCClient.init((Activity) context);
QBRTCClient.getInstance().setActivity((Activity)context);
}
:)
In my sender app I'm using
ApplicationMetadata metadata = Cast.CastApi.getApplicationMetadata(apiClient);
while
apiClient.isConnected()
returns true and my receiver app is running on the Chromecast.
When I do this, the method always returns null so the metadata object is always set to null.
Is there anything else I need to do for this to work?
Thanks in advance
There seems to be a bug there which will be addressed in the next release. Meanwhile, note that when you call Cast.CastApi.launchApplication() or Cast.CastApi.joinApplication(), you get a PendingResult object. You can set a callback on that to be notified of the result of your call; the onResult() method will be called and an ApplicationConnectionResult object will be passed to it. You can call getApplicationMetadata() on that object and that works fine (assuming you successfully launch or join an application).