我在我的应用程序中使用Google Admob广告,但我收到了很多崩溃报告,表明在admob中出现了OutOfMemoryError,
这是完整的崩溃堆栈跟踪,
java.lang.OutOfMemoryError: bitmap size exceeds VM budget
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:483)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:359)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:715)
at android.content.res.Resources.loadDrawable(Resources.java:1721)
at android.content.res.Resources.getDrawable(Resources.java:585)
at android.webkit.WebView.setOverScrollMode(WebView.java:1079)
at android.view.View.<init>(View.java:1903)
at android.view.View.<init>(View.java:1945)
at android.view.ViewGroup.<init>(ViewGroup.java:320)
at android.widget.AbsoluteLayout.<init>(AbsoluteLayout.java:52)
at android.webkit.WebView.<init>(WebView.java:997)
at android.webkit.WebView.<init>(WebView.java:980)
at android.webkit.WebView.<init>(WebView.java:970)
at android.webkit.WebView.<init>(WebView.java:961)
at com.google.android.gms.ads.internal.o.a.<init>(SourceFile:136)
at com.google.android.gms.ads.internal.o.a.a(SourceFile:124)
at com.google.android.gms.ads.internal.b.a(SourceFile:484)
at com.google.android.gms.ads.internal.request.e.run(SourceFile:191)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:138)
at android.app.ActivityThread.main(ActivityThread.java:3701)
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:878)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
at dalvik.system.NativeStart.main(Native Method)
我在xml文件中定义广告
<com.google.android.gms.ads.AdView
android:id="@+id/adView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adSize="SMART_BANNER"
ads:adUnitId="ID" />
请帮助您解决此错误?
此致
答案 0 :(得分:-1)
你可以使用我正常工作的代码我正在使用表来显示xml中的添加
这是我使用谷歌播放服务的浏览器
TableRow TR = (TableRow) findViewById(R.id.TR);
AdView adView = new AdView(this);
adView.setAdSize(AdSize.BANNER);
adView.setAdUnitId(getString("your admob id here"));
AdRequest adRequest = new AdRequest.Builder().build();
TR.addView(adView);
adView.loadAd(adRequest);
xml代码
<TableRow
android:id="@+id/TR"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal" />
清单文件
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
<meta-data
android:name="com.google.android.gms.version"
android:value="5089000" />