Learn what Felgo offers to help your business succeed. Start your free evaluation today! Felgo for Your Business

Forums

OverviewFelgo Plugins Support › AdMobInterstitial: NullPointerException

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #15154

    Paweł

    Hi,
    I’ve got problem with the AdMob plugin. When I call the showInterstitialIfLoaded method, the NullPointerException crashes my app:

    E/AndroidRuntime(18094): java.lang.NullPointerException
    E/AndroidRuntime(18094): at net.vplay.plugins.admob.AdMobInterstitialItem$3.run(AdMobInterstitialItem.java:85)
    ...

     

    This can be reproduced within the following project:

    import Felgo 3.0
    import QtQuick 2.0
    
    import Felgo 3.0
    
    GameWindow {
        id: gameWindow
    
        licenseKey: "xxx"
    
        activeScene: scene
    
        screenWidth: 640
        screenHeight: 960
    
        Scene {
            id: scene
    
            width: 320
            height: 480
    
            ButtonVPlay {
                text: qsTr("Show ad");
    
                onClicked: adMobInterstitial.showInterstitialIfLoaded();
            }
    
    
        }
    
        AdMobInterstitial {
            id: adMobInterstitial
    
            adUnitId: "ca-app-pub-xxxx/xx"
    
            onInterstitialReceived: {
                console.debug("[AdMob] Video cached");
            }
    
            onInterstitialFailedToReceive: {
                console.debug("[AdMob] Video failed to load");
            }
    
            Component.onCompleted: {
                console.debug("[AdMob] Caching video");
                loadInterstitial();
            }
    
            function showVideo() {
                if(platformSupported && platformLoaded) {
                   showInterstitialIfLoaded();
                } else {
                    console.debug("[AdMob] Not supported :(");
                }
            }
        }
    }
    

     

    The build.gradle file:

    buildscript {
        repositories {
            jcenter()
        }
    
        dependencies {
            classpath 'com.android.tools.build:gradle:1.1.0'
        }
    }
    
    allprojects {
        repositories {
            jcenter()
            maven { url 'https://sdk.felgo.com/maven/' }
        }
    }
    
    apply plugin: 'com.android.application'
    
    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
    
        compile 'net.vplay.plugins:plugin-admob:2.+'
    }
    
    android {
        /*******************************************************
         * The following variables:
         * - androidBuildToolsVersion,
         * - androidCompileSdkVersion
         * - qt5AndroidDir - holds the path to qt android files
         *                   needed to build any Qt application
         *                   on Android.
         *
         * are defined in gradle.properties file. This file is
         * updated by QtCreator and androiddeployqt tools.
         * Changing them manually might break the compilation!
         *******************************************************/
    
        compileSdkVersion androidCompileSdkVersion.toInteger()
    
        buildToolsVersion androidBuildToolsVersion
    
        sourceSets {
            main {
                manifest.srcFile 'AndroidManifest.xml'
                java.srcDirs = [qt5AndroidDir + '/src', 'src', 'java']
                aidl.srcDirs = [qt5AndroidDir + '/src', 'src', 'aidl']
                res.srcDirs = [qt5AndroidDir + '/res', 'res']
                resources.srcDirs = ['src']
                renderscript.srcDirs = ['src']
                assets.srcDirs = ['assets']
                jniLibs.srcDirs = ['libs']
           }
        }
    
        lintOptions {
            abortOnError false
        }
    }
    

     

    AndroidManifest:

    <application ... android:name="net.vplay.helper.VPlayApplication"
    
    <activity ... android:name="net.vplay.helper.VPlayActivity"

    with default permissions. I’ve tried also with custom permissions:

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    #15191

    Günther
    Felgo Team

    Hi Pawel!

    I investigated the issue and noticed that the problem lies with the loadInterstitial call.
    It seems that at the time the onCompleted handler runs the method, the plugin is not activated yet by our component that validates the plugin license. (so the item is actually not completed/usable). This results in an exception when calling showInterstitialIfLoaded.

    The plugin works if you load the interstitial at a later time (e.g. when you press the button):

    Scene {
        id: scene
        width: 320
        height: 480
    
        ButtonVPlay {
          text: qsTr("Load and show ad");
          onClicked: adMobInterstitial.loadInterstitial();
    
        }
      }
    
      AdMobInterstitial {
        id: adMobInterstitial
    
        adUnitId: "ca-app-pub-9155324456588158/9075427220"
    
        onInterstitialReceived: {
          console.debug("[AdMob] Video cached");
          // play interstitial after it was received
          adMobInterstitial.showInterstitialIfLoaded()
        }
    
        onInterstitialFailedToReceive: {
          console.debug("[AdMob] Video failed to load");
        }
    
        function showVideo() {
          if(platformSupported && platformLoaded) {
            showInterstitialIfLoaded();
          } else {
            console.debug("[AdMob] Not supported :(");
          }
        }
      }

     

    I added this issue to our bug-tracking system, we will try to fix it for one of next updates.

     

    Best,
    Günther

    #15209

    Paweł

    Hi Günther,
    it’s ok. I will load the interstitial when the result scene is opened (5 – 10 sec) after launch. Thanks for help 🙂

    Best regards,
    Paweł

     

    #15211

    Alex
    Felgo Team

    HI Pawel,

    There is actually another signal for your use-case, you can use the pluginLoaded signal instead of Component.onCompleted for caching the interstitial.

    Best,

    Alex

Viewing 4 posts - 1 through 4 (of 4 total)

RSS feed for this thread

You must be logged in to reply to this topic.

Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded