Why am I getting a java.lang.NullPointerException when I try the following code in main.lua?
Here is my main.lua. Error occurs at the admob.load line.
local admob = require( "plugin.admob" ) local function admobAdListener( event ) if ( event.phase == "init" ) then -- Successful initialization print( event.provider ) end end admob.init( admobAdListener, { appId="ca-app-pub-\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*~\*\*\*\*\*\*\*\*\*\*\*\*\*" } ) --Notice the "~" This is correct right? local function onSystemEvent( event ) if ( event.type == "applicationStart" ) then admob.load( "interstitial", { adUnitId="ca-app-pub-\*\*\*\*\*\*\*\*\*\*\*\*\*\*/\*\*\*\*\*\*\*\*\*\*\*\*" } ) end end
Here is the error when deployed on a device. Device is old (API 16) maybe thats the problem but I have successfully managed to load and show ads but in another scene. Why am I getting this error at main.lua?
The plugin must initialize properly before calling other AdMob API functions. Move admob.load() to the admobAdListener function after checking for the “init” phase.
One other issue I am having is I am loading the ads in main.lua as shown and then I go to another scene. While in main.lua I confirm that the ad is loaded with print( admob.isLoaded( “banner” ) ). It returns true after a couple of seconds.
Now when I go to another scene
local composer = require( "composer" ) local admob = require( "plugin.admob" ) function scene:show( event ) local group = self.view admob.show( "banner", { y="bottom" } ) end
the banner that is confirmed to be loaded in main.lua is not displayed and I get the error “WARNING: admob.load(adType, options), Banner not loaded”
Why is this and how can I fix it? Why am I losing the banner I loaded in the previous scene. Do I need to load() and init() in every scene?
That’s a bit strange. It shouldn’t lose the banner between scene changes. I’ll investigate once I get back on Tuesday after the holidays. In the mean time, there is no harm in issuing a load() after you change scene, however init() should only be called once.
I load a banner in main.lua and then I attempt to load a banner again at scene:show() when I change to another scene. So I am losing the previously load banner when I attempt load a new one.
This should not happen. If I am attempting to load an already loaded ad unit my attempt should be ignored and my previously load ad should not be discarded. It wasn’t being discarded in admob v2.
The plugin must initialize properly before calling other AdMob API functions. Move admob.load() to the admobAdListener function after checking for the “init” phase.
One other issue I am having is I am loading the ads in main.lua as shown and then I go to another scene. While in main.lua I confirm that the ad is loaded with print( admob.isLoaded( “banner” ) ). It returns true after a couple of seconds.
Now when I go to another scene
local composer = require( "composer" ) local admob = require( "plugin.admob" ) function scene:show( event ) local group = self.view admob.show( "banner", { y="bottom" } ) end
the banner that is confirmed to be loaded in main.lua is not displayed and I get the error “WARNING: admob.load(adType, options), Banner not loaded”
Why is this and how can I fix it? Why am I losing the banner I loaded in the previous scene. Do I need to load() and init() in every scene?
That’s a bit strange. It shouldn’t lose the banner between scene changes. I’ll investigate once I get back on Tuesday after the holidays. In the mean time, there is no harm in issuing a load() after you change scene, however init() should only be called once.
I load a banner in main.lua and then I attempt to load a banner again at scene:show() when I change to another scene. So I am losing the previously load banner when I attempt load a new one.
This should not happen. If I am attempting to load an already loaded ad unit my attempt should be ignored and my previously load ad should not be discarded. It wasn’t being discarded in admob v2.