0
可能重複:
admob 6.2.1 nullpointer exception安卓顯示java.lang.NullPointerException錯誤
,如果我想一個廣告橫幅添加到我的佈局,該錯誤只顯示了。
java.lang.NullPointerException
Exception details are logged in Window > Show View > Error Log
java.lang.NullPointerException
at com.google.ads.AdView.onMeasure(SourceFile:670)
at android.view.View.measure(View.java:15513)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4827)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
at android.view.View.measure(View.java:15513)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4827)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:15513)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4827)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
at android.view.View.measure(View.java:15513)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4827)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
at android.view.View.measure(View.java:15513)
這是我的xml文件代碼。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" >
<Button
android:id="@+id/bGoBack"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="GO BACK" />
<Button
android:id="@+id/bRefresh"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="40dp"
android:text="REFRESH" />
<Button
android:id="@+id/bForward"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="48dp"
android:text="GO FORWARD" />
<WebView
android:id="@+id/webView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="40dp" />
<com.google.ads.AdView android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="can't show my publisher id"
ads:loadAdOnCreate="true"
/>
</LinearLayout>
如果我刪除此代碼負責顯示我的xml文件中的廣告,則錯誤將消失。
<com.google.ads.AdView android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="can't show my publisher id"
ads:loadAdOnCreate="true"
/>
我無法修復錯誤,希望有更多經驗的人可以指出問題所在。謝謝!
如何添加將Api佈局設置爲10或更低?正如他的回答中所述。我想看看這是否會解決它。 – Questions
我不確定這到底是什麼意思。你可能想問他。 – Geobits
6個月前被問了! – Questions