Java Question Add listener problem (startapp lib)

Douglas Farias

Expert
Licensed User
Longtime User
Hi all.
I'm trying to use the startapp sdk and I'm having some difficulties.

the problem is in adding the interstitial callback

here's the page that talks about it.

here's the initial SDK tutorial, using the .jar file

and here is an example of a java app.


Here's what I've done so far.
B4X:
Sub Init_StartApp
    
    Private ctxt As JavaObject
    ctxt.InitializeContext
    
    'INIT SDK
    Private StartAppSDK As JavaObject
    StartAppSDK.InitializeStatic("com.startapp.sdk.adsbase.StartAppSDK")
    StartAppSDK.RunMethod("init", Array(ctxt,startAppKey,True))
    
    'SET TEST MODE
    StartAppSDK.RunMethod("setTestAdsEnabled", Array(True))
    
    'INIT ADS
    Private StartAppAd As JavaObject
    StartAppAd.InitializeStatic("com.startapp.sdk.adsbase.StartAppAd")
    
    'INIT LISTENER
    Dim AdListenerIntersticial As Object = StartAppAd.CreateEventFromUI("com.startapp.sdk.adsbase.adlisteners.AdEventListener", "AdListenerIntersticial", Null)
    
    'CALL LOAD AD WITH LISTENER
    StartAppAd.RunMethod("loadAd", Array(AdListenerIntersticial)) 'CRASH HERE
    
    
End Sub

The error log
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Error occurred on line: 80 (Main)
java.lang.IllegalArgumentException: Expected receiver of type com.startapp.sdk.adsbase.StartAppAd, but got java.lang.Class<com.startapp.sdk.adsbase.StartAppAd>
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:131)
at teste.app.iddouglasqw.main._init_startapp(main.java:437)
at teste.app.iddouglasqw.main._activity_create(main.java:393)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at teste.app.iddouglasqw.main.afterFirstLayout(main.java:105)
at teste.app.iddouglasqw.main.access$000(main.java:17)
at teste.app.iddouglasqw.main$WaitForLayout.run(main.java:83)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:201)
at android.app.ActivityThread.main(ActivityThread.java:6810)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
** Activity (main) Resume **


what can i be doing wrong? as the documentation says I must pass the listener on loadAd
Java:
startAppAd.loadAd (new AdEventListener () {
     @Override
     public void onReceiveAd (Ad ad) {
     }
     @Override
     public void onFailedToReceiveAd (Ad ad) {
     }
});


any help is welcome!
thanks
 

Douglas Farias

Expert
Licensed User
Longtime User
Really, i need some coffee :p☕.

Working code.
B4X:
    If Not(ctxt.IsInitialized) Then ctxt.InitializeContext
    
    'INIT SDK
    StartAppSDK.InitializeStatic("com.startapp.sdk.adsbase.StartAppSDK")
    StartAppSDK.RunMethod("init", Array(ctxt,startAppKey,True))
    
    'SET TEST MODE
    StartAppSDK.RunMethod("setTestAdsEnabled", Array(True))
    
    'INIT ADS
    StartAppAd.InitializeNewInstance("com.startapp.sdk.adsbase.StartAppAd", Array(ctxt))
    
    'INIT LISTENER
    Dim AdListenerIntersticial As Object = StartAppAd.CreateEventFromUI("com.startapp.sdk.adsbase.adlisteners.AdEventListener", "AdListenerIntersticial", Null)
    
    'CALL LOAD AD WITH LISTENER
    Try
        StartAppAd.RunMethod("loadAd", Array(AdListenerIntersticial))
    Catch
        Log(LastException)
    End Try

thank you!
 
Top