按下運行按鈕並將其指向我的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)
歡迎任何幫助,在此先感謝:)
NPE ??,顯示一些代碼片段,以便我們可以找到爲什麼/在哪裏NPE? – Aryan