java - 添加不在应用程序上工作的暴民

标签 java android admob

我正在尝试在我的应用程序上设置 admob 但它无法正常工作它在您必须输入用户 ID 以使 admob 服务正常工作的行中出现错误:(

package com.google.example.ads.fundamentals;

import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;

import com.google.ads.AdRequest;
import com.google.ads.AdSize;
import com.google.ads.AdView;

/**
 * A simple {@link Activity} that embeds an AdView.
 */
public class BannerSample extends Activity {
  /** The view to show the ad. */
  private AdView adView;

  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

这里有错误
//创建一个广告。 adView = new AdView(this, AdSize.BANNER, a1515******);

    // Add the AdView to the view hierarchy. The view will have no size
    // until the ad is loaded.
    LinearLayout layout = (LinearLayout) findViewById(R.id.linearLayout);
    layout.addView(adView);

    // Create an ad request. Check logcat output for the hashed device ID to
    // get test ads on a physical device.
    AdRequest adRequest = new AdRequest();
    adRequest.addTestDevice(AdRequest.TEST_EMULATOR);

    // Start loading the ad in the background.
    adView.loadAd(adRequest);
  }

  /** Called before the activity is destroyed. */
  @Override
  public void onDestroy() {
    // Destroy the AdView.
    if (adView != null) {
      adView.destroy();
    }

    super.onDestroy();
  }
}

最佳答案


我认为问题是 AdView 类中的第三个参数必须是字符串

尝试将其更改为:

 adView = new AdView(this, AdSize.BANNER, "a1515******");

希望对你有帮助

干杯,

关于java - 添加不在应用程序上工作的暴民,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15691373/

相关文章:

java - 为 Android 操作系统创建联系人列表提供商?

java - AdMob 奖励视频广告的静态奖励金额

android - 即使在关闭应用程序后仍显示 AdMob Interstitial 广告

java - android 获取adMob高度

java - 从文本文档扫描

java - 如何解决导致JAR 冲突的外部库?

android - 如何使用平台和构建工具在 RHEL linux 上安装 Android sdk

android - 列表和图片在同一个 ScrollView 中

java - TableView 中 RadioButton 的奇怪行为

java - 在 JPA 实体的基类中定义序列生成器?