如何在androidstudio中修复admob的错误消息?

qoefvg9y  于 2021-07-09  发布在  Java
关注(0)|答案(0)|浏览(304)

我已经尝试了很多年来解决这个问题,我不知道该怎么做,所以我在stackoverflow上做了一个帐户,因为在过去的几个月里这对我来说是天赐之物。在android studio中尝试使用admob加载有奖广告时,当我在关闭当前广告后粘贴代码以预加载下一个广告时,会出现三条错误消息,这些错误消息不应该出现,因为代码是正确的。我该怎么解决这个问题?我能把它上传到google play吗?下面是我的代码(错误行有星星):


**public RewardedAd createAndLoadRewardedAd() {**    (';' expected)

        RewardedAd rewardedAd = new RewardedAd(this,
                "ca-app-pub-9041707305654469/8828610380");
        RewardedAdLoadCallback adLoadCallback = new RewardedAdLoadCallback() {
            @Override
            public void onRewardedAdLoaded() {
                Log.d("TAG", "The rewarded ad loaded");
            }

            @Override
            public void onRewardedAdFailedToLoad(LoadAdError adError) {
                Log.d("TAG", "The rewarded ad failed to load");
            }
        };
        rewardedAd.loadAd(new AdRequest.Builder().build(), adLoadCallback);
      **return rewardedAd;**(cannot return value from a method with a void reusult type)
    }

    btn1 = (Button) findViewById(R.id.button);
  btn1.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
          if (rewardedAd.isLoaded()) {
              Activity activityContext = MainActivity.this;
              RewardedAdCallback adCallback = new RewardedAdCallback() {
                  @Override
                  public void onRewardedAdOpened() {
                      Log.d("TAG", "The rewarded ad opened");
                  }
                  @Override
                  public void onRewardedAdClosed() {
                    **this.rewardedAd = createAndLoadRewardedAd();**(cannot resolve symbol 'rewardedAd')
                      Log.d("TAG", "the reward ad closed");
                  }
                  @Override
                  public void onUserEarnedReward(@NonNull RewardItem reward) {
                      tvscore = (TextView) findViewById(R.id.scoretextView);
                      tvscore.setText(String.valueOf(score + fivehundred));
                      score = score + fivehundred;
                      Log.d("TAG", "user earned reward");
                  }
                  @Override
                  public void onRewardedAdFailedToShow(AdError adError) {
                      Log.d("TAG", "The rewarded ad failed to load.");
                  }
              };
              rewardedAd.show(activityContext, adCallback);
          } else {
              Log.d("TAG", "The rewarded ad wasn't loaded yet.");
          }
      }
  });

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题