当我在amulator中运行应用程序时,它运行正常,显示启动画面但不打开具有广告横幅的屏幕。当我删除活动中添加的ad bannar代码时,它会打开。代码是
<com.google.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="**********"
ads:loadAdOnCreate="true" >
</com.google.ads.AdView>
注意:我正在使用Adroid 2.2和API-8如何更改它们
当我添加此代码时,我有以下错误
04-03 13:10:44.518: W/dalvikvm(374): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
04-03 13:10:44.567: E/AndroidRuntime(374): FATAL EXCEPTION: main
04-03 13:10:44.567: E/AndroidRuntime(374): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.rms.remotedesktop1/com.rms.remotedesktop1.Home}: android.view.InflateException: Binary XML file line #30: Error inflating class com.google.ads.AdView
04-03 13:10:44.567: E/AndroidRuntime(374): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
04-03 13:10:44.567: E/AndroidRuntime(374): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-03 13:10:44.567: E/AndroidRuntime(374): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-03 13:10:44.567: E/AndroidRuntime(374): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-03 13:10:44.567: E/AndroidRuntime(374): at android.os.Handler.dispatchMessage(Handler.java:99)
04-03 13:10:44.567: E/AndroidRuntime(374): at android.os.Looper.loop(Looper.java:123)
04-03 13:10:44.567: E/AndroidRuntime(374): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-03 13:10:44.567: E/AndroidRuntime(374): at java.lang.reflect.Method.invokeNative(Native Method)
04-03 13:10:44.567: E/AndroidRuntime(374): at java.lang.reflect.Method.invoke(Method.java:521)
04-03 13:10:44.567: E/AndroidRuntime(374): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-03 13:10:44.567: E/AndroidRuntime(374): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-03 13:10:44.567: E/AndroidRuntime(374): at dalvik.system.NativeStart.main(Native Method)
04-03 13:10:44.567: E/AndroidRuntime(374): Caused by: android.view.InflateException: Binary XML file line #30: Error inflating class com.google.ads.AdView
04-03 13:10:44.567: E/AndroidRuntime(374): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:576)
04-03 13:10:44.567: E/AndroidRuntime(374): at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
04-03 13:10:44.567: E/AndroidRuntime(374): at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
04-03 13:10:44.567: E/AndroidRuntime(374): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
04-03 13:10:44.567: E/AndroidRuntime(374): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
04-03 13:10:44.567: E/AndroidRuntime(374): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
04-03 13:10:44.567: E/AndroidRuntime(374): at android.app.Activity.setContentView(Activity.java:1647)
04-03 13:10:44.567: E/AndroidRuntime(374): at com.rms.remotedesktop1.Home.onCreate(Home.java:27)
04-03 13:10:44.567: E/AndroidRuntime(374): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-03 13:10:44.567: E/AndroidRuntime(374): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
04-03 13:10:44.567: E/AndroidRuntime(374): ... 11 more
提前致谢
答案 0 :(得分:1)
尝试以编程方式添加AdView。 例:
adView = new AdView(this, AdSize.SMART_BANNER, "YOUR AD ID HERE");
LinearLayout layout = (LinearLayout) findViewById(R.id.llad);
layout.addView(adView);
AdRequest request = new AdRequest();
request.addTestDevice(AdRequest.TEST_EMULATOR);
adView.loadAd(request);