Android アプリケーションにリワード ビデオを実装したいのですが、最初にクリックしてビデオを表示するときは問題なく動作しますが、その後 2 回目または 3 回目にクリックして再度表示すると動作せず、スローされます。ログ:
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();
}}
何が間違っているかを理解するのを手伝ってもらえますか? ありがとう