gpt4 book ai didi

android - Admob 安卓 : Rewarded video not showing sometimes

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:04:26 25 4
gpt4 key购买 nike

我想在我的 android 应用程序上实现奖励视频,第一次点击显示视频时,效果很好,但在第二次或第三次点击再次显示视频时,它不起作用,并抛出日志:

W/MessageQueue: Handler (com.google.android.gms.ads.exoplayer2.upstream.u) {1e5487c} sending message to a Handler on a dead thread
java.lang.IllegalStateException: Handler (com.google.android.gms.ads.exoplayer2.upstream.u) {1e5487c} sending message to a Handler on a dead thread
at android.os.MessageQueue.enqueueMessage(MessageQueue.java:543)
at android.os.Handler.enqueueMessage(Handler.java:631)
at android.os.Handler.sendMessageAtTime(Handler.java:600)
at android.os.Handler.sendMessageDelayed(Handler.java:570)
at android.os.Handler.sendEmptyMessageDelayed(Handler.java:534)
at android.os.Handler.sendEmptyMessage(Handler.java:519)
at com.google.android.gms.ads.exoplayer2.upstream.u.run(:com.google.android.gms.DynamiteModulesA:212)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)


Could not show rewarded video ad from adapter.
java.lang.NullPointerException: Attempt to read from field 'com.google.android.gms.ads.internal.client.bq ip.a' on a null object reference
at com.google.ads.mediation.a.g(:com.google.android.gms.DynamiteModulesA:17227)
at com.google.android.gms.ads.internal.mediation.client.u.f(:com.google.android.gms.DynamiteModulesA:436)
at com.google.android.gms.ads.internal.reward.b.a(:com.google.android.gms.DynamiteModulesA:1314)
at com.google.android.gms.ads.internal.reward.client.e.onTransact(:com.google.android.gms.DynamiteModulesA:65)
at android.os.Binder.transact(Binder.java:387)
at com.google.android.gms.internal.zznu$zza$zza.show(Unknown Source)
at com.google.android.gms.internal.zzoc.show(Unknown Source)
at com.reperfection.monopoly.MainActivity$1.onClick(MainActivity.java:70)
at android.view.View.performClick(View.java:5702)
at android.view.View$PerformClick.run(View.java:22546)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7237)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Could not call showVideo.
android.os.RemoteException
at com.google.android.gms.ads.internal.mediation.client.u.f(:com.google.android.gms.DynamiteModulesA:439)
at com.google.android.gms.ads.internal.reward.b.a(:com.google.android.gms.DynamiteModulesA:1314)
at com.google.android.gms.ads.internal.reward.client.e.onTransact(:com.google.android.gms.DynamiteModulesA:65)
at android.os.Binder.transact(Binder.java:387)
at com.google.android.gms.internal.zznu$zza$zza.show(Unknown Source)
at com.google.android.gms.internal.zzoc.show(Unknown Source)
at com.reperfection.monopoly.MainActivity$1.onClick(MainActivity.java:70)
at android.view.View.performClick(View.java:5702)
at android.view.View$PerformClick.run(View.java:22546)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7237)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

这是我的代码:

public class MainActivity extends AppCompatActivity implements RewardedVideoAdListener {

TextView counterTV;
ImageView clickerBoard;
int counter;
int step = 1;
RelativeLayout parentRl;
LinearLayout ln1;
LinearLayout ln2;
private RewardedVideoAd mAd;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_left);
setContentView(R.layout.activity_main);

counterTV = (TextView) findViewById(R.id.counter);
parentRl = (RelativeLayout) findViewById(R.id.parentRl);
clickerBoard = (ImageView) findViewById(R.id.clickerBoard);
ln1 = (LinearLayout) findViewById(R.id.ln1);
ln2 = (LinearLayout) findViewById(R.id.ln2);

// Init rewarded video
mAd = MobileAds.getRewardedVideoAdInstance(this);
mAd.setRewardedVideoAdListener(this);
loadRewardedVideoAd();

ln1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (mAd.isLoaded()) {
mAd.show();
}
}
});
}

private void loadRewardedVideoAd() {
mAd.loadAd("ca-app-pub-3940256099942544/5224354917", new AdRequest.Builder().build());
}
@Override
public void onRewarded(RewardItem reward) {
Toast.makeText(this, "onRewarded! currency: " + reward.getType() + " amount: " +
reward.getAmount(), Toast.LENGTH_SHORT).show();
// Reward the user.
}

// The following listener methods are optional.
@Override
public void onRewardedVideoAdLeftApplication() {
Toast.makeText(this, "onRewardedVideoAdLeftApplication",
Toast.LENGTH_SHORT).show();
}

@Override
public void onRewardedVideoAdClosed() {
Toast.makeText(this, "onRewardedVideoAdClosed", Toast.LENGTH_SHORT).show();
loadRewardedVideoAd();
}

@Override
public void onRewardedVideoAdFailedToLoad(int errorCode) {
Toast.makeText(this, "onRewardedVideoAdFailedToLoad", Toast.LENGTH_SHORT).show();
}

@Override
public void onRewardedVideoAdLoaded() {
Toast.makeText(this, "onRewardedVideoAdLoaded", Toast.LENGTH_SHORT).show();
}

@Override
public void onRewardedVideoAdOpened() {
Toast.makeText(this, "onRewardedVideoAdOpened", Toast.LENGTH_SHORT).show();
}

@Override
public void onRewardedVideoStarted() {
Toast.makeText(this, "onRewardedVideoStarted", Toast.LENGTH_SHORT).show();
}

@Override
public void onResume() {
mAd.resume(this);
super.onResume();
}

@Override
public void onPause() {
mAd.pause(this);
super.onPause();
}

@Override
public void onDestroy() {
mAd.destroy(this);
super.onDestroy();
}}

你能帮忙找出问题所在吗?谢谢

最佳答案

解决方案

我遇到了同样的问题,正在寻找 official example我发现他们不打电话了

RewardedVideoAd.destroy(Context)

虽然他们告诉在他们的 official tutorial 中调用它.所以在删除它之后,它起作用了。

关于android - Admob 安卓 : Rewarded video not showing sometimes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44059350/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com