アプリケーションの次のコードで nullpointer 例外が発生します。
@Override
protected void onResume() {
super.onResume(); //To change body of overridden methods use File | Settings | File Templates.
// Create the adView
adView = new AdView(this, AdSize.BANNER, MY_AD_UNIT_ID);
LinearLayout layout = (LinearLayout) findViewById(R.id.ad_layout);
// Add the adView to it
layout.addView(adView); //NullPointerException here
// Initiate a generic request to load it with an ad
adView.loadAd(new AdRequest());
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
boolean isButtonLabelsEnabled = sp.getBoolean("isButtonLabelsEnabled", false);
if (!isButtonLabelsEnabled) {
stripLabels();
} else {
setContentView(R.layout.languageselection);
}
}
この問題を再現できません。エミュレーター、Galaxy S2 デバイス、ZTE ブレードの両方でアプリのすべての機能を試してみましたが、問題は見つかりませんでした。
多くのユーザーがこれを報告していますが、彼らはその理由を示していません。ただ、開こうとすると強制的に閉じられるだけです。
おそらく私はアンドロイドのライフサイクルを正しく使用していませんか?
回避策として、通過できるように AdMob のものを try/catch でラップしました。
何か案は?