admob adview causes crash on android while rotating

I added the admob adview from xml like this;

<com.google.ads.AdView
        android:id="@+id/adView"
        android:layout_above="@id/footerContainer"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        ads:adSize="BANNER"
        ads:adUnitId="..."
        ads:loadAdOnCreate="true"
        ads:testDevices="TEST_EMULATOR" />

First; there seems to be no problem. But when i change the orientation of the screen a couple of times quickly; the app crashed. I have these errors;

1- bitmap size exceeds VM budget

java.lang.OutOfMemoryError: bitmap size exceeds VM budget at android.graphics.Bitmap.nativeCreate(Native Method) at android.graphics.Bitmap.createBitmap(Bitmap.java:477) at android.graphics.Bitmap.createBitmap(Bitmap.java:444) at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:349) at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:498) at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:473) at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:336) at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697) at android.content.res.Resources.loadDrawable(Resources.java:1785) at android.content.res.TypedArray.getDrawable(TypedArray.java:601) at android.widget.ImageView.(ImageView.java:118) at android.widget.ImageButton.(ImageButton.java:85) at android.widget.ImageButton.(ImageButton.java:81) at java.lang.reflect.Constructor.constructNative(Native Method) at java.lang.reflect...

2- Binary XML file line #16: Error inflating class

android.view.InflateException: Binary XML file line #16: Error inflating class at android.view.LayoutInflater.createView(LayoutInflater.java:518) at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568) at android.view.LayoutInflater.rInflate(LayoutInflater.java:623) at android.view.LayoutInflater.inflate(LayoutInflater.java:408) at android.view.LayoutInflater.inflate(LayoutInflater.java:320) at android.view.LayoutInflater.inflate(LayoutInflater.java:276) at com.X.ui.FooterFragment.onCreateView(FooterFragment.java:21) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:846) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1061) at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:291) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:...

3- Unable to start activity ComponentInfo{com.x/com.x.ui.HomeActivity}: android.view.InflateException: Binary XML file line #13: Error inflating class

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.X/com.X.ui.HomeActivity}: android.view.InflateException: Binary XML file line #13: Error inflating class at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1768) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1784) at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:2953) at android.app.ActivityThread.access$1600(ActivityThread.java:123) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:943) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:130) at android.app.ActivityThread.main(ActivityThread.java:3835) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:507) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864) at com.android.internal.os.ZygoteInit.main(Zygo.

I tried adding it programmatically as described here, but nothing changed... Any ideas?


For 1, what SDK version are you using, and what device are you running it on? This may be an emulator specific issue.

2 and 3 are likely due to not linking the AdMob library correctly. See Error inflating class com.google.ads.AdView.

链接地址: http://www.djcxy.com/p/33654.html

上一篇: 在android中膨胀简单的xml布局时内存不足错误

下一篇: admob adview在旋转时会导致Android崩溃