java - Admob 发布 ID 错误

标签 java android sdk admob ads

我已经创建了一个付费应用程序,并且正在尝试创建带有 admob 广告的免费应用程序。我按照使用 SDK 6.1 的 Google 教程中的说明设置了整个项目,但是在运行时它不起作用。

我使用的代码与教程相同: 主.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
              android:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent">
    <TextView android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:text="@string/hello"/>
    <com.google.ads.AdView android:id="@+id/ad"
                           android:layout_width="wrap_content"
                           android:layout_height="wrap_content"
                           ads:adSize="BANNER"
                           ads:adUnitId="xxxxxxxxxx" 
                           ads:loadAdOnCreate="true"/>
</LinearLayout>

BannerSample.java 包 com.google.example.ads.xml;

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

/**
 * A simple {@link Activity} which embeds an AdView in its layout XML.
 */
public class BannerSample extends Activity {
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // This example requires no additional code since the optional
    // "loadAdOnCreate=true" XML attribute was used. If "loadAdOnCreate" were
    // not specified, the ad would have to be loaded by creating an AdRequest
    // and using Activity.findViewById() to get the AdView.
    //
    // The "loadAdOnCreate" XML attribute makes it simpler to get ads since no
    // code is required, but it also limits the developer's control over the ad
    // request since a generic AdRequest is used.
  }
}

我得到的错误:

07-28 21:34:48.704: E/Ads(15980): JS: Uncaught ReferenceError: AFMA_getSdkConstants is not defined (about:blank:1)
07-28 21:34:48.704: E/Web Console(15980): Uncaught ReferenceError: AFMA_getSdkConstants is not defined at about:blank:1
07-28 21:36:48.841: E/Ads(15980): JS: Uncaught ReferenceError: AFMA_getSdkConstants is not defined (about:blank:1)
07-28 21:36:48.841: E/Web Console(15980): Uncaught ReferenceError: AFMA_getSdkConstants is not defined at about:blank:1
07-28 21:38:48.958: E/Ads(15980): JS: Uncaught ReferenceError: AFMA_getSdkConstants is not defined (about:blank:1)
07-28 21:38:48.958: E/Web Console(15980): Uncaught ReferenceError: AFMA_getSdkConstants is not defined at about:blank:1
07-28 21:40:49.066: E/Ads(15980): JS: Uncaught ReferenceError: AFMA_getSdkConstants is not defined (about:blank:1)
07-28 21:40:49.066: E/Web Console(15980): Uncaught ReferenceError: AFMA_getSdkConstants is not defined at about:blank:1
07-28 21:42:02.817: E/chromium(17098): external/chromium/net/disk_cache/stat_hub.cc:190: [0728/214202:ERROR:stat_hub.cc(190)] StatHub::Init - App com.google.example.ads.xml isn't supported.
07-28 21:42:02.827: E/chromium(17098): external/chromium/net/disk_cache/stat_hub.cc:190: [0728/214202:ERROR:stat_hub.cc(190)] StatHub::Init - App com.google.example.ads.xml isn't supported.
07-28 21:42:03.178: E/Ads(17098): JS: Uncaught ReferenceError: AFMA_getSdkConstants is not defined (about:blank:1)
07-28 21:42:03.198: E/Web Console(17098): Uncaught ReferenceError: AFMA_getSdkConstants is not defined at about:blank:1

感谢您的帮助!

更新: 新代码和错误是: BannerSample.java

package com.google.example.ads.xml;

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

import android.app.Activity;
import android.os.Bundle;
import android.os.Looper;

/**
 * A simple {@link Activity} which embeds an AdView in its layout XML.
 */
public class BannerSample extends Activity {
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // This example requires no additional code since the optional
    // "loadAdOnCreate=true" XML attribute was used. If "loadAdOnCreate" were
    // not specified, the ad would have to be loaded by creating an AdRequest
    // and using Activity.findViewById() to get the AdView.
    //
    // The "loadAdOnCreate" XML attribute makes it simpler to get ads since no
    // code is required, but it also limits the developer's control over the ad
    // request since a generic AdRequest is used.
    (new Thread() {
        public void run() {
             Looper.prepare();
             AdView view = (AdView) findViewById(R.id.ad);
             view.loadAd(new AdRequest());
        }
    }).start();
  }
}

错误:

07-28 21:42:02.817: E/chromium(17098): external/chromium/net/disk_cache/stat_hub.cc:190: [0728/214202:ERROR:stat_hub.cc(190)] StatHub::Init - App com.google.example.ads.xml isn't supported.
07-28 21:42:02.827: E/chromium(17098): external/chromium/net/disk_cache/stat_hub.cc:190: [0728/214202:ERROR:stat_hub.cc(190)] StatHub::Init - App com.google.example.ads.xml isn't supported.

更新 2: 对不起,我忘了发布 list :

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.google.example.ads.xml"
          android:versionCode="1"
          android:versionName="1.0">
    <uses-sdk android:targetSdkVersion="15" android:minSdkVersion="3"/> 

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.INTERNET"/>

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <meta-data android:value=" a1501435dfa5050 " android:name="ADMOB_PUBLISHER_ID" />
        <activity android:name=".BannerSample"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity android:name="com.google.ads.AdActivity"
                  android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
    </application>
</manifest>

最佳答案

(new Thread() {
            public void run() {
                 Looper.prepare();
                adView.loadAd(new AdRequest());
            }
        }).start();

在 ICS 中,您不能在主线程中执行网络操作

关于java - Admob 发布 ID 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11704120/

相关文章:

java - struts.action.excludePattern 不工作

java - 调用 PaintComponent 时数组的大小变为 0

java - 将使用 Netbeans 创建的 Java 程序固定在任务栏上?

java - 在 styles.xml 文件中为所有按钮声明一个通用的 onClick 属性

android - 华为 Watch 2 NFC 功能不可用?安卓穿戴 2.0

Android API 14 - 网络操作/AsyncTask

android - 执行 android 工具命令时看不到 Android SDK 和 AVD Manager

ios - Swift Facebook 登录错误 "Apple Mach-O Linker Error"

java - 如何使用字符串路径名在 WAR 中打开资源文件?

java - 使用 "key"和 "value"属性反序列化 JSON 映射不适用于 Jackson