2017-09-06 130 views
0

按下運行按鈕並將其指向我的adb設備後,我的應用出現問題(HTC One M9 Plus運行2.30.401.1,Android 6.0 if你不知道HTC的版本號,如果它有任何區別)。嘗試使用AdMob時出現Android Studio錯誤(運行時崩潰)

下面是Android Studio中的logcat的日誌

java.lang.RuntimeException: Unable to start activity 
java.lang.NullPointerException: Attempt to invoke virtual method 'void com.google.android.gms.ads.AdView.loadAd(com.google.android.gms.ads.AdRequest)' on a null object reference 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2611)                    
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2677) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1515) 
at android.os.Handler.dispatchMessage(Handler.java:111) 
at android.os.Looper.loop(Looper.java:227) 
at android.app.ActivityThread.main(ActivityThread.java:6100) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:859) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:749) 
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 
'void com.google.android.gms.ads.AdView.loadAd(com.google.android.gms.ads.AdRequest)' 
on a null object reference 
at com.groverstudios.applestore.MainActivity.onCreate(MainActivity.java:39) 
at android.app.Activity.performCreate(Activity.java:6280) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1131) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2564) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2677)  
at android.app.ActivityThread.-wrap11(ActivityThread.java)  
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1515)  
at android.os.Handler.dispatchMessage(Handler.java:111)  
at android.os.Looper.loop(Looper.java:227)  
at android.app.ActivityThread.main(ActivityThread.java:6100)  
at java.lang.reflect.Method.invoke(Native Method)  
at co m.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:859)  
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:749)  

歡迎任何幫助,在此先感謝:)

+1

NPE ??,顯示一些代碼片段,以便我們可以找到爲什麼/在哪裏NPE? – Aryan

回答

1

你的錯誤說不太清楚發生了什麼

java.lang.NullPointerException: Attempt to invoke virtual method 'void com.google.android.gms.ads.AdView.loadAd(com.google.android.gms.ads.AdRequest)' on a null object reference 

所以你有一個成員或變量指向AdView,這是空的。 在調用.loadAd(...)方法之前,您需要執行.findViewById(R.id.name_of_your_adview)

+0

Ahhhhhh非常感謝你!現在一切都說得通了! –

+0

接受答案是一個很好的方式來說聲謝謝:) - 很高興我能幫忙! – Grisgram

相關問題