Hi, we are facing the following exception in Android, after reviewing firebase dashboard we’ve found the following stack trace:
Caused by java.lang.NullPointerException: Attempt to invoke virtual method ‘int java.lang.String.hashCode()’ on a null object reference
at com.unity3d.player.ReflectionHelper$a.(:19)
at com.unity3d.player.ReflectionHelper.getMethodID(:2)
Hi! We also have a ton of crashes with this stack trace:
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.hashCode()' on a null object reference
at com.unity3d.player.ReflectionHelper$a.<init>
at com.unity3d.player.ReflectionHelper.getMethodID
We updated Unity from 2020.1.17f1 to 2020.3.34f1 but it looks like it had no effect on the issue
We also see very similar fatal exception in Crashlytics Dashboard. The amount of crashes is critical, because of this exception. Will be good Unity developers response to this thread.
96% of crash devices has OS: Android 12
4% of crash devices has OS: Android 13
We are using Unity 2020.3.41f1 version.
Caused by java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.hashCode()' on a null object reference
at com.unity3d.player.ReflectionHelper$a.<init>(:19)
at com.unity3d.player.ReflectionHelper.getFieldID(:10)
Hi,
I’m currently adding AdMob to my project and I have the same error sometimes, do you use AdMob too ? maybe it’s related because I did not have this but before.
I have InApp purchasing in my game v. 4.4.1. WHen game started I got warning message:
Unity IAP: Unity In-App Purchasing requires Unity Gaming Services to have been initialized before use
I added init code:
const string k_Environment = "production";
void Initialize(Action onSuccess, Action<string> onError)
{
try
{
var options = new InitializationOptions().SetEnvironmentName(k_Environment);
UnityServices.InitializeAsync(options).ContinueWith(task => onSuccess());
}
catch (Exception exception)
{
onError(exception.Message);
}
}
void OnSuccess()
{
var text = "Congratulations!\nUnity Gaming Services has been successfully initialized.";
informationText.text = text;
Debug.Log(text);
}
void OnError(string message)
{
var text = $"Unity Gaming Services failed to initialize with error: {message}.";
informationText.text = text;
Debug.LogError(text);
}
And when I added this code I got this error.
Update: when I changed code to
const string k_Environment = "production";
async void Initialize(Action onSuccess, Action<string> onError)
{
try
{
var options = new InitializationOptions().SetEnvironmentName(k_Environment);
await UnityServices.InitializeAsync(options);
OnSuccess();
}
catch (Exception exception)
{
onError(exception.Message);
}
}
void OnSuccess()
{
var text = "Congratulations!\nUnity Gaming Services has been successfully initialized.";
informationText.text = text;
Debug.Log(text);
}
void OnError(string message)
{
var text = $"Unity Gaming Services failed to initialize with error: {message}.";
informationText.text = text;
Debug.LogError(text);
}
java.lang.NullPointerException: Attempt to invoke virtual method ‘int java.lang.Object.hashCode()’ on a null object reference
at com.unity3d.player.ReflectionHelper$a.(Unknown Source:11)
at com.unity3d.player.ReflectionHelper.getMethodID(Unknown Source:2)
unity 2019.4.10 I met the same problem,
I also encountered the same problem, but I can’t reproduce it locally. Can anyone provide a stable reproduction step?
Unity version : 2020.3.25f1c1
Android OS: 12+
Target:31
OK, find a way to reproduce the bug using AdMob at 100%
public void CreateAndLoadRewardedAd()
{
#if UNITY_ANDROID
string adUnitId = "ca-app-pub-3940256099942544/5224354917";
#elif UNITY_IPHONE
string adUnitId = "ca-app-pub-3940256099942544/1712485313";
#else
string adUnitId = "unexpected_platform";
#endif
this.rewardedAd = new RewardedAd(adUnitId);
this.rewardedAd.OnAdLoaded += HandleRewardedAdLoaded;
this.rewardedAd.OnUserEarnedReward += HandleUserEarnedReward;
this.rewardedAd.OnAdClosed += HandleRewardedAdClosed;
// Create an empty ad request.
AdRequest request = new AdRequest.Builder().Build();
// Load the rewarded ad with the request.
this.rewardedAd.LoadAd(request);
}
public async void HandleRewardedAdClosed(object sender, EventArgs args)
{
await Task.Delay(2000);
CreateAndLoadRewardedAd(); // here the crash happen !
}
Just trying to reload the ad after an async delay makes the app crash.
In case of load failed I added a reload after a delay and the crash happend in these case.
We do not use Admob but we are also getting this error:
Unity 2020.3.30f1
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.hashCode()' on a null object reference
at com.unity3d.player.ReflectionHelper$a.<init>
at com.unity3d.player.ReflectionHelper.getMethodID
After making the update available on the store I have lot of errors spamming in the Android Vital page, I deactivate the ads and the errors stopped.
Anyone finds a way to correct this error ?
Maybe someone from Unity could read this topic and gives some help ?
It kind of worked as before the fix I had 100% reproductible bug and after I never reproduce it on my test devices. In production I have still some crash because of this bug (1000 crash on 400 unique users on 15 days on my game with near 10000 daily users).
But this bug has caused my game to reach the crash rate limit on google play store, so I had to disable AdMob for the moment. I’m currently trying to resolve the issue (changing ad mediation partner) to be able te re-activate ads on my game.