0

当我运行它时,它会给出一个 java 堆空间错误,并再次给出消息“您的项目包含错误,请在运行前修复它们”,并再次显示与“发生内部错误请关闭工作台”相关的消息。我也使用移动设备的测试ID,但每次都会出现相同的错误。

布局文件:

activity_main.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/res-auto"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical">

         <com.google.android.gms.ads.AdView`enter code here`
            android:id="@+id/adView"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            ads:adSize=" SMART_BANNER "
            ads:adUnitId="ca-app-pub-7222219345251053/8664557124" />

    </LinearLayout>

newadmobtutorialmanifest.xml

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.androidbegin.newadmobtutorial"
        android:versionCode="1"
        android:versionName="1.0" >

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

        <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
        <uses-permission android:name="android.permission.INTERNET" />
     <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
        <application
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >
            <activity
                android:name=".MainActivity"
                android:label="@string/title_activity_main" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />

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

            <meta-data
                android:name="com.google.android.gms.version"
                android:value="@integer/google_play_services_version" />

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

    </manifest>

mainActivity.java

    package com.androidbegin.newadmobtutorial;

    import com.google.android.gms.ads.AdListener;
    import com.google.android.gms.ads.AdRequest;
    import com.google.android.gms.ads.AdSize;
    import com.google.android.gms.ads.AdView;
    import com.google.android.gms.ads.InterstitialAd;

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

    public class MainActivity extends Activity {
        private InterstitialAd interstitial;

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            // Get the view from activity_main.xml
            setContentView(R.layout.activity_main);

            // Prepare the Interstitial Ad
            interstitial = new InterstitialAd(MainActivity.this);
            // Insert the Ad Unit ID
            interstitial.setAdUnitId("ca-app-pub-7222219345251053/8664557124");

            //Locate the Banner Ad in activity_main.xml
            AdView adView = (AdView) this.findViewById(R.id.adView);

            // Request for Ads
            AdRequest adRequest = new AdRequest.Builder()

            // Add a test device to show Test Ads
            // .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
            // .addTestDevice("EB81B984CF6F807FED26757A39F8FF")
                    .build();

            // Load ads into Banner Ads
            adView.loadAd(adRequest);

            // Load ads into Interstitial Ads
            interstitial.loadAd(adRequest);

            // Prepare an Interstitial Ad Listener
            interstitial.setAdListener(new AdListener() {
                public void onAdLoaded() {
                    // Call displayInterstitial() function
                    displayInterstitial();
                }
            });
        }
        public void displayInterstitial() {
            // If Ads are loaded, show Interstitial else show nothing.
            if (interstitial.isLoaded()) {
                interstitial.show();
            }
        }
    }

这是我的eclipse.ini

-startup
plugins/org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_1.1.200.v20120913-144807
-product
com.android.ide.eclipse.adt.package.adtproduct
-showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
512m
--launcher.defaultAction
openFile
-vmargs “c:\Program Files\Java\jdk1.7.0_07\bin\javaw.exe”
-Dosgi.requiredJavaVersion=1.7
-XX:MaxPermSize=2028m
-XX:CompileThreshold=5
-XX:MaxGCPauseMillis=10
-XX:MaxHeapFreeRatio=70
-Xms2028m
-Xmx6120m
4

1 回答 1

0

Try to set adUnitId from dynamicly, e.g.

<uradreference>.setAdUnitId("ca-app-pub-7409237681170791/6275305467");

also try with ads:adSize="BANNER" first! It should work.

于 2014-12-06T10:47:15.590 回答