广告错误 - android

时间:2014-09-17 16:44:56

标签: android

直到在应用上投放广告,该应用运行良好。在我添加广告代码后,当我尝试运行时,应用停止。

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错误:

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错误:

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.

1 个答案:

答案 0 :(得分:0)

您必须将以下标记放在<application>的{​​{1}}标记内:

AndroidManifest.xml