0

我正在尝试制作提供“100 个硬币”的广告,并且该按钮在 0,2 - 1 秒后消失。

我不知道为什么会出现这个错误。有人知道如何解决这个问题吗?

我的错误

    06-03 21:42:16.017: V/PTAdHeyzapBridge(27950): PTAdHeyzapBridge -- Start Session: "MyHeyzapID"
    06-03 21:42:16.023: E/Heyzap(27950): Heyzap encountered a runtime exception and is now disabled. Error: Attempt to invoke virtual method 'java.lang.String android.content.Context.getPackageName()' on a null object reference
    06-03 21:42:16.023: V/PTAdHeyzapBridge(27950): PTAdHeyzapBridge -- Start Session FAILED : Attempt to invoke virtual method 'java.lang.String android.content.Context.getPackageName()' on a null object reference
    06-03 21:42:16.023: V/PTAdHeyzapBridge(27950): Heyzap SDK Version : 8.4.1

我的 PTAdHeyzapBridge.java

package com.secrethq.ads;

import java.lang.ref.WeakReference;

import org.cocos2dx.lib.Cocos2dxActivity;

import com.google.android.gms.ads.AdView;
import com.heyzap.sdk.ads.HeyzapAds;
import com.heyzap.sdk.ads.InterstitialAd;
import com.heyzap.sdk.ads.VideoAd;
import com.heyzap.sdk.ads.IncentivizedAd;
import com.heyzap.sdk.ads.BannerAdView;
import com.heyzap.sdk.ads.HeyzapAds.BannerListener;
import com.heyzap.sdk.ads.HeyzapAds.BannerError;
import com.heyzap.sdk.ads.HeyzapAds.OnStatusListener;
import com.heyzap.sdk.ads.HeyzapAds.OnIncentiveResultListener;

import android.util.Log;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;

public class PTAdHeyzapBridge {
    private static native String bannerId();
    private static native String interstitialId();
    private static native void interstitialDidFail();
    private static native void bannerDidFail();
    private static native void rewardVideoComplete();

    private static final String TAG = "PTAdHeyzapBridge";
    private static Cocos2dxActivity activity;
    private static WeakReference<Cocos2dxActivity> s_activity;
    private static  BannerAdView bannerAdView;

    public static void initBridge(Cocos2dxActivity activity){
        Log.v(TAG, "PTAdHeyzapBridge -- INIT");
        PTAdHeyzapBridge.s_activity = new WeakReference<Cocos2dxActivity>(activity);    
        PTAdHeyzapBridge.activity = activity;

        PTAdHeyzapBridge.initBanner();
        PTAdHeyzapBridge.initInterstitial();
        PTAdHeyzapBridge.initVideo();
    }

    public static void initBanner(){
        Log.v(TAG, "PTAdHeyzapBridge -- Init Banner");

        PTAdHeyzapBridge.s_activity.get().runOnUiThread( new Runnable() {
            public void run() {
                PTAdHeyzapBridge.bannerAdView = new BannerAdView(PTAdHeyzapBridge.activity);

                FrameLayout frameLayout = (FrameLayout)PTAdHeyzapBridge.activity.findViewById(android.R.id.content);
                RelativeLayout layout = new RelativeLayout( PTAdHeyzapBridge.activity );
                frameLayout.addView( layout );

                RelativeLayout.LayoutParams adViewParams = new RelativeLayout.LayoutParams(
                        AdView.LayoutParams.WRAP_CONTENT,
                        AdView.LayoutParams.WRAP_CONTENT);
                adViewParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
                adViewParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);

                layout.addView(PTAdHeyzapBridge.bannerAdView, adViewParams);
                PTAdHeyzapBridge.bannerAdView.setVisibility( View.INVISIBLE );

                // Add a listener.
                PTAdHeyzapBridge.bannerAdView.setBannerListener(new BannerListener() {
                    @Override
                    public void onAdClicked(BannerAdView b) {
                        // The ad has been clicked by the user.
                    }

                    @Override
                    public void onAdLoaded(BannerAdView b) {
                        // The ad has been loaded.
                    }

                    @Override
                    public void onAdError(BannerAdView b, BannerError bannerError) {
                        // There was an error loading the ad.
                        Log.v(TAG, "PTAdHeyzapBridge -- Banner onAdError : " + bannerError.getErrorMessage());
                        bannerDidFail();
                    }
                });
            }
        });
    }

    public static void initInterstitial(){
        Log.v(TAG, "PTAdHeyzapBridge -- Init Interstitial");        

        InterstitialAd.setOnStatusListener(new OnStatusListener() {
            @Override
            public void onShow(String tag) {
                // Ad is now showing
            }

            @Override
            public void onClick(String tag) {
                // Ad was clicked on. You can expect the user to leave your application temporarily.
            }

            @Override
            public void onHide(String tag) {
                // Ad was closed. The user has returned to your application.
            }

            @Override
            public void onFailedToShow(String tag) {
                // Display was called but there was no ad to show
            }

            @Override
            public void onAvailable(String tag) {
                // An ad has been successfully fetched
            }

            @Override
            public void onFailedToFetch(String tag) {
                // No ad was able to be fetched
                Log.v(TAG, "PTAdHeyzapBridge -- Interstitial onFailedToFetch : " + tag);
                interstitialDidFail();
            }

            @Override
            public void onAudioFinished() {
                // TODO Auto-generated method stub

            }

            @Override
            public void onAudioStarted() {
                // TODO Auto-generated method stub

            }
        });

    }

    public static void initVideo() {
        IncentivizedAd.setOnIncentiveResultListener(new OnIncentiveResultListener() {
            @Override
            public void onComplete(String tag) {
                Log.v(TAG, "PTAdHeyzapBridge -- IncentivizedAd Complete ");

                // Give the player their reward
                rewardVideoComplete();
            }

            @Override
            public void onIncomplete(String tag) {
                // Don't give the player their reward, and tell them why
                Log.v(TAG, "PTAdHeyzapBridge -- IncentivizedAd InComplete ");
            }
        });

        PTAdHeyzapBridge.s_activity.get().runOnUiThread( new Runnable() {
            public void run() {
                // As early as possible, and after showing a rewarded video, call fetch
                IncentivizedAd.fetch();
            }
        });
    }

    public static void showRewardedVideo(){
        Log.v(TAG, "PTAdHeyzapBridge -- showRewardedVideo");

        PTAdHeyzapBridge.s_activity.get().runOnUiThread( new Runnable() {
            public void run() {
                if (IncentivizedAd.isAvailable()) {
                    IncentivizedAd.display(PTAdHeyzapBridge.activity);
                }
            }
        });

    }

    public static void startSession( String sdkKey ){
        if(sdkKey != null){
            Log.v(TAG, "PTAdHeyzapBridge -- Start Session: " + sdkKey);

            try {
                HeyzapAds.start(sdkKey, PTAdHeyzapBridge.activity);
            } catch (Exception e) {
                // TODO: handle exception
                Log.v(TAG, "PTAdHeyzapBridge -- Start Session FAILED : " + e.getMessage());
            }

            Log.v(TAG, "Heyzap SDK Version : " + HeyzapAds.getVersion());

        }else{
            Log.v(TAG, "Start Session : null ");
        }
    }

    public static void showFullScreen(){
        Log.v(TAG, "PTAdHeyzapBridge -- showFullScreen");

        PTAdHeyzapBridge.s_activity.get().runOnUiThread( new Runnable() {
            public void run() {
                // InterstitialAds are automatically fetched from our server
                InterstitialAd.display(PTAdHeyzapBridge.activity);
            }
        });
    }

    public static void showBannerAd(){
        Log.v(TAG, "PTAdHeyzapBridge -- showBannerAd");

        PTAdHeyzapBridge.s_activity.get().runOnUiThread( new Runnable() {
            public void run() {
                if(PTAdHeyzapBridge.bannerAdView != null){
                    PTAdHeyzapBridge.bannerAdView.setVisibility(View.VISIBLE);
                    // Load the banner ad.
                    PTAdHeyzapBridge.bannerAdView.load();
                }
            }
        });
    }

    public static void hideBannerAd(){
        Log.v(TAG, "PTAdHeyzapBridge -- hideBannerAd");
        PTAdHeyzapBridge.s_activity.get().runOnUiThread( new Runnable() {
            public void run() {
                if(PTAdHeyzapBridge.bannerAdView != null){
                    PTAdHeyzapBridge.bannerAdView.setVisibility(View.INVISIBLE);
                }
            }
        });
    }

    public static boolean isBannerVisible() {   
        return (PTAdHeyzapBridge.bannerAdView.getVisibility() == View.VISIBLE);
    }

    public static boolean isRewardedVideoAvialable(){   
        return IncentivizedAd.isAvailable();
    }
}

我的主要活动

package com.lopeostudios.runningpanda;

import org.cocos2dx.lib.Cocos2dxActivity;
import org.cocos2dx.lib.Cocos2dxGLSurfaceView;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.WindowManager;
import android.widget.Toast;
import com.secrethq.store.PTStoreBridge;
import com.google.android.gms.games.GamesActivityResultCodes;
import com.lopeostudios.runningpanda.R;
import com.secrethq.ads.*;
import com.secrethq.utils.*;
import com.onesignal.OneSignal;


public class PTPlayer extends Cocos2dxActivity {


    private static native void loadModelController();

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        Log.v("----------","onActivityResult: request: " + requestCode + " result: "+ resultCode);
        if(PTStoreBridge.iabHelper().handleActivityResult(requestCode, resultCode, data)){
            Log.v("-----------", "handled by IABHelper");
        }
        else if(requestCode == PTServicesBridge.RC_SIGN_IN){
            if(resultCode == RESULT_OK){
                PTServicesBridge.instance().onActivityResult(requestCode, resultCode, data);
            }
            else if(resultCode == GamesActivityResultCodes.RESULT_SIGN_IN_FAILED){
                int duration = Toast.LENGTH_SHORT;
                Toast toast = Toast.makeText(this, "Google Play Services: Sign in error", duration);
                toast.show();
            }
            else if(resultCode == GamesActivityResultCodes.RESULT_APP_MISCONFIGURED){
                int duration = Toast.LENGTH_SHORT;
                Toast toast = Toast.makeText(this, "Google Play Services: App misconfigured", duration);
                toast.show();               
            }
        }
    }

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        OneSignal.startInit(this).init();
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    }



    @Override
    public void onNativeInit(){
            initBridges();              
    }

    private void initBridges(){
        PTStoreBridge.initBridge( this );
        PTServicesBridge.initBridge(this, getString( R.string.app_id ));

        if (PTJniHelper.isAdNetworkActive("kChartboost")) {
            PTAdChartboostBridge.initBridge(this);
        }

        if (PTJniHelper.isAdNetworkActive("kRevMob")) {
            PTAdRevMobBridge.initBridge(this);
        }

        if (PTJniHelper.isAdNetworkActive("kAdMob") || PTJniHelper.isAdNetworkActive("kFacebook")) {
            PTAdAdMobBridge.initBridge(this);
        }

        if (PTJniHelper.isAdNetworkActive("kAppLovin")) {
            PTAdAppLovinBridge.initBridge(this);
        }

        if (PTJniHelper.isAdNetworkActive("kLeadBolt")) {
            PTAdLeadBoltBridge.initBridge(this);
        }

        if (PTJniHelper.isAdNetworkActive("kVungle")) {
            PTAdVungleBridge.initBridge(this);
        }

        if (PTJniHelper.isAdNetworkActive("kPlayhaven")) {
            PTAdUpsightBridge.initBridge(this);
        }

        if (PTJniHelper.isAdNetworkActive("kMoPub")) {
            PTAdMoPubBridge.initBridge(this);
        }

        if (PTJniHelper.isAdNetworkActive("kFacebook")) {
            PTAdFacebookBridge.initBridge(this);
        }

        if (PTJniHelper.isAdNetworkActive("kHeyzap")) {
            PTAdHeyzapBridge.initBridge(this);
        }

    }



    @Override
    public Cocos2dxGLSurfaceView onCreateView() {
        Cocos2dxGLSurfaceView glSurfaceView = new Cocos2dxGLSurfaceView(this);
        glSurfaceView.setEGLConfigChooser(8, 8, 8, 0, 0, 0);

        return glSurfaceView;
    }

    static {
        System.loadLibrary("player");
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (PTJniHelper.isAdNetworkActive("kChartboost")) {
            PTAdChartboostBridge.onResume( this );
        }
    }

    @Override
    protected void onStart() {
        super.onStart();
        if (PTJniHelper.isAdNetworkActive("kChartboost")) {
            PTAdChartboostBridge.onStart( this );
        }
    }

    @Override
    protected void onStop() {
        super.onStop();
        if (PTJniHelper.isAdNetworkActive("kChartboost")) {
            PTAdChartboostBridge.onStop( this );
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }




}
4

1 回答 1

0

我是 Heyzap 的工程师。我们的 SDK 会捕获来自第三方 SDK 的异常,如果我们捕获到异常则关闭我们的 SDK(这是我们防止异常导致游戏崩溃的最后一道防线)。在这种情况下,我们捕捉到了这个异常:

06-03 21:42:16.023: E/Heyzap(27950): Heyzap encountered a runtime exception and is now disabled. Error: Attempt to invoke virtual method 'java.lang.String android.content.Context.getPackageName()' on a null object reference

我们之前看到过由过时的 UnityAds SDK 引起的异常。您是否使用该网络,如果是,您可以尝试UnityAds 1.5.6吗?如果你不是,你能告诉我们你正在使用哪些网络,或者你的游戏的 Android 包吗?

另外,我在您的日志中看到您使用的是去年 6 月发布的 Heyzap 8.4.1。你能更新到我们的最新版本吗?

于 2016-06-03T21:52:40.127 回答