O
O
ocelotman2020-08-01 13:37:31
Unity
ocelotman, 2020-08-01 13:37:31

NullReferenceException: Object reference not set to an instance of an object is thrown when I want to play award video. What to do?

I have a problem, when I run Rewarded ad in my application, I get a NullReferenceException: Object reference not set to an instance of an object.

private RewardBasedVideoAd rewardBasedVideo;

    public void Start()
    {
        MobileAds.Initialize(initStatus => { });
        
        this.rewardBasedVideo = RewardBasedVideoAd.Instance;

        this.RequestRewardBasedVideo();

        this.rewardBasedVideo.OnAdLoaded += this.HandleRewardBasedVideoLoaded;
        this.rewardBasedVideo.OnAdFailedToLoad += this.HandleRewardBasedVideoFailedToLoad;
        this.rewardBasedVideo.OnAdOpening += this.HandleRewardBasedVideoOpened;
        this.rewardBasedVideo.OnAdStarted += this.HandleRewardBasedVideoStarted;
        this.rewardBasedVideo.OnAdRewarded += this.HandleRewardBasedVideoRewarded;
        this.rewardBasedVideo.OnAdClosed += this.HandleRewardBasedVideoClosed;
        this.rewardBasedVideo.OnAdLeavingApplication += this.HandleRewardBasedVideoLeftApplication;
    }

    private void RequestRewardBasedVideo()
    {
        string adUnitId = "ca-app-pub-3940256099942544/5224354917";

        AdRequest request = new AdRequest.Builder().Build();
        this.rewardBasedVideo.LoadAd(request, adUnitId);
    }

    public void UserOptToWatchAd()
    {
        if (rewardBasedVideo.IsLoaded())
        {
            rewardBasedVideo.Show();
        }
    }


I did everything as in the guide from Google, but I get this error. If you click on it, it moves to the line "if (rewardBasedVideo.IsLoaded())". Please help me fix this

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey, 2020-08-02
@aDOPPIO

What version of the plugin do you have in unity?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question