Java Question Banner cannot be cast to android.view.View

Douglas Farias

Expert
Licensed User
Longtime User
Hi all.

I'm trying to use the Display io SDK to make a library.
I've already managed to do all the interstitial part, but now in the banner I got to a part that I don't know how to follow.


Java:
public void onLoaded(Ad ad) {
    switch (adUnitType){
        case "BANNER" :{
            try {
                BannerPlacement bannerPlacement = (BannerPlacement) Controller.getInstance().getPlacement(placementId);
                View bannerView = bannerPlacement.getBanner(BannerAndMediumRectangleActivity.this, adRequest.getId());
                adLayout.addView(bannerView);
                adLayout.setVisibility(View.VISIBLE);
            } catch (DioSdkException e) {
                Log.e(TAG, e.getLocalizedMessage());
            }
            break;
        }

I m already get the onLoaded event, but i dont know how transform a banner to view.

B4X:
Sub adLoadBanner_Event (MethodName As String, Args() As Object) As Object
    Log(MethodName) '= onLoaded
    Log(Args.Length) '= 1
    If MethodName = "onLoaded" Then
        Private v As View = Args(0) '< CRASH HERE
    Else if MethodName = "onFailedToLoad" Then
        Log("error: " & Args(0))
    End If
    Return Null
End Sub

The code above cause a crash, here is the log.
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
controller initialized
onAdReceived
onLoaded
1
aqui
starter_adloadbanner_event (java line: 234)
java.lang.ClassCastException: com.brandio.ads.ads.Banner cannot be cast to android.view.View
at b4a.example.starter._adloadbanner_event(starter.java:234)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
at anywheresoftware.b4a.BA$1.run(BA.java:352)
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)
starter_adloadbanner_event (java line: 234)
java.lang.ClassCastException: com.brandio.ads.ads.Banner cannot be cast to android.view.View
at b4a.example.starter._adloadbanner_event(starter.java:234)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
at anywheresoftware.b4a.BA$1.run(BA.java:352)
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)


what would be the correct way to transform the banner into a view?

Here is the java example

And here is this part on the sdk tutorial

Edit: I've already tried get it as javaobject and later add it to activity, but show me the same log....

Thank you!
 
Top