ClassCastException Error on LIB Wrapper

DevBaby

Active Member
Licensed User
Longtime User
Looking to create wrapper for the following SDK calls:

1) HeyzapLib.load(this);

Instructions say...

The load function takes one argument, which must be a Context object. It does not modify the context object, so in most cases you will pass in either this or this.getContext().


2) HeyzapLib.checkin(this, "I beat the monster on level 2!");

-------------------------------------

The first call request for "context" object, but maybe I am sending the wrong context object.

When calling HeyzapLib.load, nothing happens but a form is suppose to load.



When calling HeyzapLib.checkin, I get ClassException: android.app.Application cannot be cast to android.app,Activity


My wrapper code is here...

B4X:
package com.leaderboard;

import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.DependsOn;
import anywheresoftware.b4a.BA.Permissions;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;

import com.heyzap.sdk.HeyzapLib;

@DependsOn(values={"heyzapsdk"})
@Permissions(values={"android.permission.INTERNET"})
@ShortName("HZ_LeaderBoard")
@Version(1.0f)

public class leaderboardclass {

   public void HzRegister(final BA ba){

      HeyzapLib.load(BA.applicationContext.getApplicationContext());
      
   }

   public void HzCheckin(final BA ba, String Msg){

            
      HeyzapLib.checkin(BA.applicationContext.getApplicationContext(), Msg);
      
   }
   
   public void HzSubmitscore(String Score, String ScoreMsg, String LevelId){

      HeyzapLib.submitScore(BA.applicationContext.getApplicationContext(), Score, ScoreMsg, LevelId);
      
   }

   public void HzShowLeaderBoard(){

      HeyzapLib.showLeaderboards(BA.applicationContext.getApplicationContext());
      
   }
   
}
 
Last edited:

warwound

Expert
Licensed User
Longtime User
It looks as if you're passing the Application Context NOT the Activity Context.

Try changing all references:

B4X:
package com.leaderboard;

import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.DependsOn;
import anywheresoftware.b4a.BA.Permissions;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;

import com.heyzap.sdk.HeyzapLib;

@DependsOn(values={"heyzapsdk"})
@Permissions(values={"android.permission.INTERNET"})
@ShortName("HZ_LeaderBoard")
@Version(1.0f)

public class leaderboardclass {

    public void HzRegister(final BA ba){

        HeyzapLib.load(ba.context);
        
    }

    public void HzCheckin(final BA ba, String Msg){

                
        HeyzapLib.checkin(ba.context, Msg);
        
    }
    
    public void HzSubmitscore(final BA ba, String Score, String ScoreMsg, String LevelId){

        HeyzapLib.submitScore(ba.context, Score, ScoreMsg, LevelId);
        
    }

    public void HzShowLeaderBoard(final BA ba){

        HeyzapLib.showLeaderboards(ba.context);
        
    }
    
}

Also look at the @ActivityObject annotation, it may be required if this library creates Views.

Martin.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…