こんにちは私InterstitialAdにに(RadioListElementのRLE)プレイと呼ばれる方法が私のアプリで実行するたびに実行したいが、それは私にこのエラーが発生しますjava.lang.NullPointerExceptionが
クラス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(); } }
ログ
26421-26421/com.radio.stations E/GooglePlayServicesUtil:Google Playサービスのリソースが見つかりませんでした。リソースが含まれていることを確認するには、プロジェクトの構成を確認してください。 07-18 16:52:59.049 26421-26421/com.radio.stations W/System.err:java.lang.NullPointerException:仮想メソッド 'android.content.pm.PackageInfo android.content.pm.PackageManagerを呼び出そうとしていますnullオブジェクト参照の.getPackageInfo(java.lang.String、int) ' 07-18 16:52:59.049 26421-26421/com.radio.stations W/System.err:com.google.android.gms。 common.zze.isGooglePlayServicesAvailable(不明な情報源) 07-18 16:52:59.049 26421-26421/com.radio.stations W/System.err:com.google.android.gms.common.zzc.isGooglePlayServicesAvailable(不明な情報源) 07-18 16:52:59.049 26421-26421/com.radio.stations W/System.err:com.google.android.gms.ads.internal.util.client.zza.zzar(不明な情報源) 07-18 16:52:59.049 26421-26421/com.radio.stations W/System.err:com.google.android.gms.ads.internal.client.zzl.zza(不明な情報源) 07-18 16:52:59.049 26421-26421/com.radio.stations W/System.err:com.google.android.gms.ads.internal.client.zzl.zzb(不明な情報源) 07-18 16:52:59.049 26421-26421/com.radio.stations W/System.err:com.google.android.gms.ads.internal.client.zzaf.zzam(不明な情報源) 07-18 16:52: 59.049 26421-26421/com.radio.stations W/System.err:com.google.android.gms.ads.internal.client.zzaf.zza(不明な情報源) 07-18 16:52:59.049 26421-26421 /com.radio.stations W/System.err:com.google.android.gms.ads.InterstitialAd.loadAd(不明な情報源) 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:com.Radio。 Stations.RadioList.nextOrPreviousRadioStation(RadioList.java:82) 07-18 16:52:59.049 26421-26421/com.radio.stations W/System.err:com.Radio.Stations.MusicPlayerControl $ 2.onTouch(MusicPlayerControl.java:94) 07-18 16:52: 59.049 26421から26421/com.radio.stations W/System.errの:android.view.View.dispatchTouchEvent(View.java:8802)で
build.gradleプロジェクト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'}
なぜ「コンテキスト」を拡張するのですか? –
あなたもbuild.gradleファイルを投稿できますか? – Bill
延長を削除すると返信いただきありがとうございます。** "InterstitialAd(android.content。InterstitialAd = new InterstitialAd(this); in "this" ok –