简体   繁体   中英

I am adding admob ads in my android application but having exception inflating class com.google.ads.AdView

When i run app in amulator it runs fine, shows splash screen but does not open screen having ads banner. When i remove the code for ad bannar which is added in activity then it open. The code is

<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>

Note: I am using Adroid 2.2 and API-8 how can i change them

when i add this code I have following error

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

Thanks in advance

Try add the AdView programmatically. Ex.:

   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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM