Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
adView.loadAd()正在崩溃android应用程序_Android_Eclipse - Fatal编程技术网

adView.loadAd()正在崩溃android应用程序

adView.loadAd()正在崩溃android应用程序,android,eclipse,Android,Eclipse,我正在尝试在我的应用程序上设置Google play services广告。但是,每当我尝试呼叫时 adView.loadAd() 它使应用程序崩溃。如果我在这行评论,广告不会崩溃,但窗口不会出现。我试着研究关于这个话题的类似问题,但找不到适合我的解决方案。任何帮助都将不胜感激 这是我的主要观点: protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); s

我正在尝试在我的应用程序上设置Google play services广告。但是,每当我尝试呼叫时

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>
日志:

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

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

您不了解的是,您必须在元素中有以下声明:?我的错,我在活动下有标记,而不是在应用程序下。这就是我如此困惑的原因,因为我知道我已经在那里添加了元数据标签。谢谢