Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Ads plugin:NullPointerException issues — Gideros Forum

Ads plugin:NullPointerException issues


We are experiencing a lot of crashes regarding the ads plugin but we're not sure what is causing the issue.

We initialize ads ONCE at the start of the game. Is this the best approach? How do you implement ads in your game?

Could our issues be related to pause / resume?

Here's an example of a recent crash:

at com.giderosmobile.android.plugins.ads.frameworks.AdsAdmob.showAd (AdsAdmob.java:416)
at com.giderosmobile.android.plugins.ads.Ads$8.run (Ads.java:355)
at android.os.Handler.handleCallback (Handler.java:739)
at android.os.Handler.dispatchMessage (Handler.java:95)
at android.os.Looper.loop (Looper.java:148)
at android.app.ActivityThread.main (ActivityThread.java:7325)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1120

We are using Gideros 2018.10

Does anyone have any ideas?



Likes: Apollo14

+1 -1 (+1 / -0 )Share on Facebook


  • I suppose it's all in how you use the plugin? My setup is pretty much as basic as it can get with just banner adverts showing. In my main.lua I have..
    ADMOB_APP_ID = 'your admob app id goes here'
    ADMOB_UNIT_ID = 'your admob unit id goes here'
    -- admob (setup for simple banner adverts)
    if DEBUGGING then
      ADMOB = {} -- create fake object for testing in windows player
      ADMOB.loadAd = function() end
      ADMOB.showAd = function() end
      require 'ads' --create real object for on device
      ADMOB = Ads.new('admob')
      ADMOB:addEventListener(Event.AD_RECEIVED, function() -- show ad
        ADMOB:setAlignment('center', 'bottom')
      ADMOB:addEventListener(Event.AD_FAILED, function(e) end)
      ADMOB:addEventListener(Event.AD_ACTION_BEGIN, function() end)
      ADMOB:addEventListener(Event.AD_ACTION_END, function() end)
      ADMOB:addEventListener(Event.AD_DISMISSED, function() end)
    Then in my game scene I have..
    function Game:init()
    -- start showing banner adverts
    function Game:startAds()
      if PREFS.showAds then
        ADMOB:loadAd("banner", ADMOB_UNIT_ID)
    I haven't personally seen the plugin crash when suspending and resuming, and I've done extensive suspend/resume testing with ads recently whilst fixing a bug with one of my games.
    If I was concerned that suspend/resume might be an issue I'd probably throw some more code into my game scene..
    -- add listeners, start logic
    function Game:onTransitionInEnd()
      self:addEventListener(Event.APPLICATION_RESUME, self.onApplicationResume, self)
      self:addEventListener(Event.APPLICATION_SUSPEND, self.onApplicationSuspend, self)
    function Game:onApplicationSuspend()
    function Game:onApplicationResume()
    I might be wrong here but looking through the AdsAdmob source file it seems that at line 416 it is having an issue with rewarded video adverts, somebody who knows more about the workings of the plugin could say more.. or correct me if I'm wrong ;)

    Likes: Apollo14, simwhi

    +1 -1 (+2 / -0 )Share on Facebook
  • simwhisimwhi Member
    edited December 2018
    @antix That is correct for the original source but I made some modifications to add in GDPR consent logic. I didn't change any other code relating to serving ads though. So, in my case the line number points to the showAd method.
  • hgy29hgy29 Maintainer
    @simwhi, if you are using a custom version of AdsAdmob.java then it is hard of us to help you without seeing what there is at that line (and what variable could be null)
    +1 -1 (+2 / -0 )Share on Facebook
  • antixantix Member
    edited December 2018
    @simwhi ahh, you didn't say you were using a modified source :D
  • simwhisimwhi Member
    edited December 2018
    Sorry guys. It was a general enquiry about the NullPointerException in the showAd method. Here's the code:
    public void showAd(final Object parameters)
    Log.i("AdsAdmob", "showAd");
    SparseArray param = (SparseArray)parameters;
    String type = param.get(0);
    if(adsManager.get(type) == null)

    Line 416 relates to loadAd(parameters);
  • hgy29hgy29 Maintainer
    edited December 2018
    This is strange, because, that line can't trigger a NPE: it doesn't try to access an object's field.
    In this method, I can see only two ways to get a NPE:
    1° parameter is null, thus param.get(0) will trigger NPE
    2° adsManager is null, and either adsManager.get(type) or adsManager.show(type) will trigger NPE

    Maybe AdsManager was cleared up (app closing) before the event was triggered ?

    Likes: simwhi

    +1 -1 (+1 / -0 )Share on Facebook
  • hgy29hgy29 Maintainer
    @simwhi, any chance you could share you modified AdMob plugin or make a pull request to gideros github ?
  • @hgy29 I would ordinarily be very happy to share the code but the consent implementation was very hacky. At the time I needed to get it working quickly but lacked the knowledge to do it correctly.

    This is what I did:
    1. I added code to the adsAdmob. java to determine whether the user is in the EEA or not using the the Google consent API on initialization.
    2. I hijacked the error event to send EEA or non EEA back to Lua.
    3. We show a GDPR dialogue for EEA users to accept NPA ads only. We decided not to show personalized ads.
    4. The user cannot use our app unless they consent to NPA. We save this consent in our user preferences file.

    If you would like any code snippets I am happy to assist.


Sign In or Register to comment.