I created my app and now I'm trying to add AdMob Ads but I'm stuck with an instant crash and a problem and I don't know how to fix it.
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.glitchrun.sapphire/com.glitchrun.sapphire.PTPlayer}: 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:2957)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3032)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6944)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
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.glitchrun.sapphire.PTPlayer.onCreate(PTPlayer.java:68)
at android.app.Activity.performCreate(Activity.java:7183)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1220)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2910)
I tried to remove import com.google.android.gms.ads.AdView;
but after that ads are not showing in the app. BUT I still have requests in AdMob and matchrate even if ads are not showing. How to solve the problem?
import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
AdView mAdView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);`