admob 6.2.1 空指针异常

时间:2022-11-25
本文介绍了admob 6.2.1 空指针异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大问题,我想将 admob 集成到我的 android 应用程序中,但是当我尝试将 admob 集成到 xml 文件中时,我在图形布局中得到了一个空指针异常

i have a big problem, i want to integrate admob in my android app but i get a nullpointer exception in the graphical layout when i try to integrate admob in the xml file

java.lang.NullPointerException
    at com.google.ads.AdView.onMeasure(SourceFile:670)
    at android.view.View.measure(View.java:15172)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814)
    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1390)
    at android.widget.LinearLayout.measureVertical(LinearLayout.java:681)
    at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
    at android.view.View.measure(View.java:15172)
    at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:617)
    at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:399)
    at android.view.View.measure(View.java:15172)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
    at android.view.View.measure(View.java:15172)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814)
    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1390)
    at android.widget.LinearLayout.measureVertical(LinearLayout.java:681)
    at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
    at android.view.View.measure(View.java:15172)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814)
    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1390)
    at android.widget.LinearLayout.measureVertical(LinearLayout.java:681)
    at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
    at android.view.View.measure(View.java:15172)
    at com.android.layoutlib.bridge.impl.RenderSessionImpl.measureView(RenderSessionImpl.java:542)
    at com.android.layoutlib.bridge.impl.RenderSessionImpl.render(RenderSessionImpl.java:444)
    at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:333)
    at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:325)
    at com.android.ide.eclipse.adt.internal.editors.layout.gle2.RenderService.createRenderSession(RenderService.java:372)
    at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.renderWithBridge(GraphicalEditorPart.java:1638)
    at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.recomputeLayout(GraphicalEditorPart.java:1389)
    at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.activated(GraphicalEditorPart.java:1163)
    at com.android.ide.eclipse.adt.internal.editors.layout.LayoutEditorDelegate.delegatePageChange(LayoutEditorDelegate.java:674)
    at com.android.ide.eclipse.adt.internal.editors.common.CommonXmlEditor.pageChange(CommonXmlEditor.java:360)
    at org.eclipse.ui.part.MultiPageEditorPart$2.widgetSelected(MultiPageEditorPart.java:292)
    at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:248)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1077)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1062)
    at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:774)
    at org.eclipse.swt.custom.CTabFolder.setSelection(CTabFolder.java:3023)
    at org.eclipse.swt.custom.CTabFolder.onMouse(CTabFolder.java:1730)
    at org.eclipse.swt.custom.CTabFolder$1.handleEvent(CTabFolder.java:270)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
    at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4169)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3758)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1022)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:916)
    at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:86)
    at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:585)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
    at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:540)
    at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
    at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:124)
    at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:353)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1438)
    at org.eclipse.equinox.launcher.Main.main(Main.java:1414)

这是xml文件

<RelativeLayout xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/backgroundapp"
android:orientation="vertical" >



<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_alignParentBottom="true"
  android:orientation="vertical"
  android:gravity="bottom"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">

    <ListView android:id="@id/android:list"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:cacheColorHint="#00000000"
    android:textColor="#FFFFFF"/>

    <Button
    android:id="@+id/add_main_btn"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:text="@string/add_serie" />

</LinearLayout>



<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" android:layout_alignParentTop="true" android:id="@+id/ad_layout" android:orientation="vertical" android:gravity="top" android:layout_width="fill_parent" android:layout_height="fill_parent">

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

</LinearLayout>

</RelativeLayout>

这里是我的班级

adView = new AdView(this, AdSize.BANNER, MY_AD_UNIT_ID);
    LinearLayout layout = (LinearLayout)findViewById(R.id.adView);
    layout.addView(adView);
    adView.loadAd(new AdRequest());

感谢您的回复.

添加另一个 XML 布局文件相同的错误

add an other XML Layout File same Error

<RelativeLayout 
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/backgroundapp"
android:orientation="vertical">

    <Button
        android:id="@+id/add_main_btn"
        android:layout_width="fill_parent"
        android:layout_height="70dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:text="@string/add_serie" />

    <ListView
        android:id="@id/android:list"
        android:layout_width="fill_parent"
        android:layout_height="541dp"
        android:layout_alignParentLeft="true"
        android:cacheColorHint="#00000000"
        android:textColor="#FFFFFF" >

    </ListView>

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

已解决的问题 Admob 6.2.1 有一个针对 Android 4.1.2 的错误,将 Api 布局设置为 10 或更低,有新的错误消息但不影响程序或广告

Problem solved Admob 6.2.1 has a bug for Android 4.1.2 set the Api layout to 10 or lower, have new error messages but doesnt effect the programm or ad

推荐答案

onMeasure 中的NullPointerException 在查看AdView 图形布局时一个已知问题.它将在下一个主要版本中修复.

The NullPointerException in onMeasure when viewing an AdView the graphical layout is a known issue. It will be fixed for the next major release.

与此同时,编辑原始 XML 或在代码中定义 AdView 工作正常.

In the meantime, editing the raw XML or defining an AdView in code works just fine.

这篇关于admob 6.2.1 空指针异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

上一篇:如何在 IntelliJ IDEA 中设置 SDK? 下一篇:Couchbase 存储桶身份验证错误

相关文章

最新文章