adView.loadAd()崩溃Android应用程序

时间:2014-07-07 02:24:54

标签: android eclipse

我正在尝试在我的应用上设置Google Play服务广告。但是每当我尝试拨打电话时

adView.loadAd() 

它崩溃了应用程序。如果我注释掉这一行,广告不会崩溃,但窗口不会显示。我已经尝试过关于这个主题的类似问题,但找不到适用于我的解决方案。任何帮助将不胜感激。

这是我的主要内容:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    // Look up the AdView as a resource and load a request.
    AdView adView = (AdView)this.findViewById(R.id.adView1);
    AdRequest adRequest = new AdRequest.Builder().build();
    adView.loadAd(adRequest); // this is what seems to be causing the problem

清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.williampatrickweld2.deckofcardsworkoutfree"
    android:versionCode="3"
    android:versionName="1.2" >

    <uses-sdk
        android:minSdkVersion="9"
        android:targetSdkVersion="19" />

    <supports-screens
        android:smallScreens="true"
        android:normalScreens="true"
        android:largeScreens="true"
        android:resizeable="true"
        />
    <application

        android:allowBackup="true"
        android:icon="@raw/docmedium"
        android:label="@string/app_name"
        android:theme="@style/AppThemeNoTitleBar" >
        <activity

            android:name="com.williampatrickweld2.deckofcardsworkoutfree.MainActivity"
            android:screenOrientation="portrait"
            android:label="@string/app_name">
            <meta-data android:name="com.google.android.gms.version"
           android:value="@integer/google_play_services_version" />
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

        </activity>
        <activity android:name="com.google.android.gms.ads.AdActivity"
                   android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|s    mallestScreenSize"/>
    </application>
    <uses-permission android:name="android.permission.INTERNET"/>
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

</manifest>

logcat的:

07-06 20:42:36.593: I/Process(21454): Sending signal. PID: 21454 SIG: 9
07-06 20:42:52.420: D/skia(21817): ---- fAsset->read(2450) returned 0
07-06 20:42:52.570: D/AndroidRuntime(21817): Shutting down VM
07-06 20:42:52.570: W/dalvikvm(21817): threadid=1: thread exiting with uncaught         exception (group=0x41815da0)
07-06 20:42:52.570: E/AndroidRuntime(21817): FATAL EXCEPTION: main
07-06 20:42:52.570: E/AndroidRuntime(21817): Process: c     com.williampatrickweld2.deckofcardsworkoutfree, PID: 21817
07-06 20:42:52.570: E/AndroidRuntime(21817): java.lang.RuntimeException: Unable to   start activity    ComponentInfo{com.williampatrickweld2.deckofcardsworkoutfree/com.williampatrickweld2.deckof    cardsworkoutfree.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" />
07-06 20:42:52.570: E/AndroidRuntime(21817):    at   android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2334)
07-06 20:42:52.570: E/AndroidRuntime(21817):    at   android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2392)
07-06 20:42:52.570: E/AndroidRuntime(21817):    at  android.app.ActivityThread.access$900(ActivityThread.java:169)
07-06 20:42:52.570: E/AndroidRuntime(21817):    at   android.app.ActivityThread$H.handleMessage(ActivityThread.java:1280)  
07-06 20:42:52.570: E/AndroidRuntime(21817):    at  android.os.Handler.dispatchMessage(Handler.java:102)
07-06 20:42:52.570: E/AndroidRuntime(21817):    at  android.os.Looper.loop(Looper.java:146)
07-06 20:42:52.570: E/AndroidRuntime(21817):    at  android.app.ActivityThread.main(ActivityThread.java:5487)
07-06 20:42:52.570: E/AndroidRuntime(21817):    at  java.lang.reflect.Method.invokeNative(Native Method)
07-06 20:42:52.570: E/AndroidRuntime(21817):    at  java.lang.reflect.Method.invoke(Method.java:515)
07-06 20:42:52.570: E/AndroidRuntime(21817):    at  com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
07-06 20:42:52.570: E/AndroidRuntime(21817):    at  com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
07-06 20:42:52.570: E/AndroidRuntime(21817):    at   dalvik.system.NativeStart.main(Native Method)
07-06 20:42:52.570: E/AndroidRuntime(21817): 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" />
07-06 20:42:52.570: E/AndroidRuntime(21817):    at   com.google.android.gms.common.GooglePlayServicesUtil.x(Unknown Source)
07-06 20:42:52.570: E/AndroidRuntime(21817):    at    com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown  Source)
07-06 20:42:52.570: E/AndroidRuntime(21817):    at com.google.android.gms.internal.ai.a(Unknown Source)
07-06 20:42:52.570: E/AndroidRuntime(21817):    at  com.google.android.gms.internal.av.aH(Unknown Source)
07-06 20:42:52.570: E/AndroidRuntime(21817):    at com.google.android.gms.internal.av.a(Unknown Source)
07-06 20:42:52.570: E/AndroidRuntime(21817):    at  com.google.android.gms.ads.AdView.loadAd(Unknown Source)
07-06 20:42:52.570: E/AndroidRuntime(21817):    at com.williampatrickweld2.deckofcardsworkoutfree.MainActivity.onCreate(MainActivity.java:70)
07-06 20:42:52.570: E/AndroidRuntime(21817):    at android.app.Activity.performCreate(Activity.java:5451)
07-06 20:42:52.570: E/AndroidRuntime(21817):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
07-06 20:42:52.570: E/AndroidRuntime(21817):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
07-06 20:42:52.570: E/AndroidRuntime(21817):    ... 11 more
07-06 20:42:54.712: I/Process(21817): Sending signal. PID: 21817 SIG: 9

1 个答案:

答案 0 :(得分:0)

您必须在清单中添加元数据,您可以在logcat中看到它: 您应用的AndroidManifest.xml中的必需元数据标记不存在。您必须在元素中包含以下声明: 添加元数据,您的应用程序将正常工作