首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Heyzap按钮一直在消失

Heyzap按钮一直在消失
EN

Stack Overflow用户
提问于 2016-06-03 19:49:06
回答 1查看 460关注 0票数 0

我试着制作广告,给出"100枚硬币“,然后按钮在0,2 -1秒后消失。

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

我的错误

代码语言:javascript
复制
    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

My PTAdHeyzapBridge.java

代码语言:javascript
复制
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();
    }
}

我的主要活动

代码语言:javascript
复制
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();
    }




}
EN

回答 1

Stack Overflow用户

发布于 2016-06-03 21:52:40

我是Heyzap的工程师。我们的SDK将捕获来自第三方SDK的异常,如果我们捕捉到一个SDK,则关闭SDK(这是防止异常破坏游戏的最后一道防线)。在本例中,我们捕捉到了这个异常:

代码语言:javascript
复制
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包?

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37622319

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档