Admob 6.2.1 исключение nullpointer

У меня большая проблема, я хочу интегрировать admob в мое приложение для Android, но я получаю исключение nullpointer в графическом макете, когда я пытаюсь интегрировать admob в xml файл

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.*******.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.*******.launcher.Main.invokeFramework(Main.java:629)
 at org.eclipse.*******.launcher.Main.basicRun(Main.java:584)
 at org.eclipse.*******.launcher.Main.run(Main.java:1438)
 at org.eclipse.*******.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">
 </listview></linearlayout></relativelayout><button android:id="@+id/add_main_btn" android:layout_width="fill_parent" android:layout_height="match_parent" android:text="@string/add_serie"><code>&lt;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"&gt;
 &lt;/linearlayout&gt;</code>
<p> и здесь мой класс</p>
<pre class="prettyprint linenums">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 с той же ошибкой

<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">
 </relativelayout>
2 ответа

NullPointerException в onMeasure при просмотре AdView графическая компоновка является известной проблемой. Он будет исправлен для следующего основного релиза.

Тем временем редактирование необработанного XML или определение AdView в коде работает очень хорошо.


В дизайне макета есть ошибка, чтобы попытаться закодировать его в коде или просто сгенерировать макет, а затем в конечном итоге реализовать рекламные строки xml.

licensed under cc by-sa 3.0 with attribution.