Hello I want to run an InterstitialAd Every time the method called play(RadioListElement rle) execute in my app but it gives me this error
Class MusicPlayer
public class MusicPlayer extends Context {
private static MediaPlayer mediaPlayer;
private InterstitialAd InterstitialAd;
private AdRequest adsRequest;
public void play(RadioListElement rle) {
radioListElement = rle;
playMusic(radioListElement.getUrl());
adsRequest = new AdRequest.Builder().build();
/*Prepare the Interstitial Ad*/
InterstitialAd = new InterstitialAd(this);
/* Insert the Ad Unit ID */
InterstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712");
InterstitialAd.loadAd(adsRequest);
/* Prepare an Interstitial Ad Listener*/
InterstitialAd.setAdListener(new AdListener() {
public void onAdLoaded () {
displayInterstitial(); } }); }
private void displayInterstitial() {
if (InterstitialAd.isLoaded()) {
InterstitialAd.show(); } }
LOG
26421-26421/com.radio.stations E/GooglePlayServicesUtil: The Google Play services resources were not found. Check your project configuration to ensure that the resources are included. 07-18 16:52:59.049 26421-26421/com.radio.stations W/System.err: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.pm.PackageInfo android.content.pm.PackageManager.getPackageInfo(java.lang.String, int)' on a null object reference 07-18 16:52:59.049 26421-26421/com.radio.stations W/System.err: at com.google.android.gms.common.zze.isGooglePlayServicesAvailable(Unknown Source) 07-18 16:52:59.049 26421-26421/com.radio.stations W/System.err: at com.google.android.gms.common.zzc.isGooglePlayServicesAvailable(Unknown Source) 07-18 16:52:59.049 26421-26421/com.radio.stations W/System.err: at com.google.android.gms.ads.internal.util.client.zza.zzar(Unknown Source) 07-18 16:52:59.049 26421-26421/com.radio.stations W/System.err: at com.google.android.gms.ads.internal.client.zzl.zza(Unknown Source) 07-18 16:52:59.049 26421-26421/com.radio.stations W/System.err: at com.google.android.gms.ads.internal.client.zzl.zzb(Unknown Source) 07-18 16:52:59.049 26421-26421/com.radio.stations W/System.err: at com.google.android.gms.ads.internal.client.zzaf.zzam(Unknown Source) 07-18 16:52:59.049 26421-26421/com.radio.stations W/System.err: at com.google.android.gms.ads.internal.client.zzaf.zza(Unknown Source) 07-18 16:52:59.049 26421-26421/com.radio.stations W/System.err: at com.google.android.gms.ads.InterstitialAd.loadAd(Unknown Source) 07-18 16:52:59.049 26421-26421/com.radio.stations W/System.err: at com.Radio.Stations.MusicPlayer.play(MusicPlayer.java:125) 07-18 16:52:59.049 26421-26421/com.radio.stations W/System.err: at com.Radio.Stations.RadioList.nextOrPreviousRadioStation(RadioList.java:82) 07-18 16:52:59.049 26421-26421/com.radio.stations W/System.err: at com.Radio.Stations.MusicPlayerControl$2.onTouch(MusicPlayerControl.java:94) 07-18 16:52:59.049 26421-26421/com.radio.stations W/System.err: at android.view.View.dispatchTouchEvent(View.java:8802)
build.gradle project com.radio.stations
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.Switzerland.radio.stations"
multiDexEnabled true
minSdkVersion 14
targetSdkVersion 23
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' } }}
dependencies {
compile project(':initActivity')
compile 'com.android.support:support-v4:24.0.0'
compile 'com.google.android.gms:play-services:9.2.0'}