首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Ads错误- android

Ads错误- android
EN

Stack Overflow用户
提问于 2014-09-17 16:44:56
回答 1查看 140关注 0票数 0

在应用程序上投放广告之前,应用程序运行良好。在我为广告添加了代码之后,当我尝试运行它时,应用程序就停止了。

代码语言:javascript
复制
private AdView adView;


    private static final String AD_UNIT_ID = "ca-app-pub-7628432187347131/3277094808";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        getSupportActionBar().hide();
        // Create an ad.
        adView = new AdView(this);
        adView.setAdSize(AdSize.SMART_BANNER);
        adView.setAdUnitId(AD_UNIT_ID);

        context = this;
        LinearLayout layout = (LinearLayout) findViewById(R.id.ads_lin);
        layout.addView(adView);

        AdRequest adRequest = new AdRequest.Builder()
                .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
                .addTestDevice("5B895A3CC0CA50D56506E300A4C8342B")
                .addTestDevice("D039292A1F434C999B21503D63D6FD88")

                .addTestDevice("TEST_EMULATOR").build();

        // Start loading the ad in the background.

        adView.loadAd(adRequest);

这是logcat错误:

代码语言:javascript
复制
09-17 19:42:40.142: E/dalvikvm(24843): adjustAdaptiveCoef max=4194304, min=1048576, ut=568
09-17 19:42:40.352: E/AndroidRuntime(24843): FATAL EXCEPTION: main
09-17 19:42:40.352: E/AndroidRuntime(24843): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.stiaica/com.example.stiaica.MainActivity}: java.lang.IllegalStateException: A required meta-data tag in your app's AndroidManifest.xml does not exist.  You must have the following declaration within the <application> element:     <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
09-17 19:42:40.352: E/AndroidRuntime(24843):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2245)
09-17 19:42:40.352: E/AndroidRuntime(24843):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2299)
09-17 19:42:40.352: E/AndroidRuntime(24843):    at android.app.ActivityThread.access$700(ActivityThread.java:150)
09-17 19:42:40.352: E/AndroidRuntime(24843):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1280)
09-17 19:42:40.352: E/AndroidRuntime(24843):    at android.os.Handler.dispatchMessage(Handler.java:99)
09-17 19:42:40.352: E/AndroidRuntime(24843):    at android.os.Looper.loop(Looper.java:137)
09-17 19:42:40.352: E/AndroidRuntime(24843):    at android.app.ActivityThread.main(ActivityThread.java:5283)
09-17 19:42:40.352: E/AndroidRuntime(24843):    at java.lang.reflect.Method.invokeNative(Native Method)
09-17 19:42:40.352: E/AndroidRuntime(24843):    at java.lang.reflect.Method.invoke(Method.java:511)
09-17 19:42:40.352: E/AndroidRuntime(24843):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
09-17 19:42:40.352: E/AndroidRuntime(24843):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
09-17 19:42:40.352: E/AndroidRuntime(24843):    at dalvik.system.NativeStart.main(Native Method)
09-17 19:42:40.352: E/AndroidRuntime(24843): Caused by: java.lang.IllegalStateException: A required meta-data tag in your app's AndroidManifest.xml does not exist.  You must have the following declaration within the <application> element:     <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
09-17 19:42:40.352: E/AndroidRuntime(24843):    at com.google.android.gms.common.GooglePlayServicesUtil.A(Unknown Source)
09-17 19:42:40.352: E/AndroidRuntime(24843):    at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
09-17 19:42:40.352: E/AndroidRuntime(24843):    at com.google.android.gms.internal.ah.a(Unknown Source)
09-17 19:42:40.352: E/AndroidRuntime(24843):    at com.google.android.gms.internal.au.aM(Unknown Source)
09-17 19:42:40.352: E/AndroidRuntime(24843):    at com.google.android.gms.internal.au.a(Unknown Source)
09-17 19:42:40.352: E/AndroidRuntime(24843):    at com.google.android.gms.ads.AdView.loadAd(Unknown Source)
09-17 19:42:40.352: E/AndroidRuntime(24843):    at com.example.stiaica.MainActivity.onCreate(MainActivity.java:49)
09-17 19:42:40.352: E/AndroidRuntime(24843):    at android.app.Activity.performCreate(Activity.java:5283)
09-17 19:42:40.352: E/AndroidRuntime(24843):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097)
09-17 19:42:40.352: E/AndroidRuntime(24843):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2209)
09-17 19:42:40.352: E/AndroidRuntime(24843):    ... 11 more

在我添加清单之后出现了一个新错误。我可以运行这个应用程序,但广告不适用。Logcat错误:

代码语言:javascript
复制
09-17 19:59:17.485: E/GooglePlayServicesUtil(29878): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
09-17 19:59:17.915: E/GooglePlayServicesUtil(29878): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
09-17 19:59:18.016: E/GooglePlayServicesUtil(29878): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
09-17 19:59:18.016: E/GooglePlayServicesUtil(29878): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
09-17 19:59:51.648: E/GooglePlayServicesUtil(29878): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
09-17 19:59:51.688: E/GooglePlayServicesUtil(29878): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
09-17 19:59:51.738: E/GooglePlayServicesUtil(29878): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
09-17 19:59:51.768: E/GooglePlayServicesUtil(29878): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
09-17 20:00:22.909: E/GooglePlayServicesUtil(29878): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
09-17 20:00:22.929: E/GooglePlayServicesUtil(29878): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
09-17 20:00:22.939: E/GooglePlayServicesUtil(29878): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
09-17 20:00:22.949: E/GooglePlayServicesUtil(29878): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
09-17 20:00:53.989: E/GooglePlayServicesUtil(29878): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
09-17 20:00:54.009: E/GooglePlayServicesUtil(29878): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
09-17 20:00:54.019: E/GooglePlayServicesUtil(29878): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
09-17 20:00:54.019: E/GooglePlayServicesUtil(29878): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-09-17 16:55:47

您必须将以下标记放入<application>标记中的AndroidManifest.xml

代码语言:javascript
复制
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25896049

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档