1

ユーザーがadviewをクリックした後、広告の読み込みを停止したいのですが、すでにadlistenerを実装し、adView.stopLoading();を配置しました。onDismissScreenで表示されますが、広告Webページを閉じると次のエラーが発生します。

E/AndroidRuntime(1059): java.lang.RuntimeException: Unable to pause activity {ivn.com.teletextinternational/com.google.ads.AdActivity}: java.lang.NullPointerException

コード:

public class MyActivity extends Activity implements OnClickListener, AdListener {
RelativeLayout relativeLayout1;
 ImageView imgpag; 
 FrameLayout frameLayout1;
 FrameLayout frameLayout2;
 Button right;
 Button left;
 ProgressBar probar;
 LinearLayout linear;
 AdView adView;
 EditText numbox;

 public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    imgpag = (ImageView)findViewById (R.id.imgpag); 
    relativeLayout1 = (RelativeLayout) findViewById(R.id.RelativeLayout1);
    frameLayout1 = (FrameLayout) findViewById(R.id.frameLayout1);
    frameLayout2 = (FrameLayout) findViewById(R.id.frameLayout2);
    left = (Button) findViewById(R.id.left);
    right = (Button) findViewById(R.id.right);
    probar = (ProgressBar) findViewById (R.id.probar);
    adView = new AdView(this, AdSize.BANNER, "a14ebbcd3aae1ff");

    LinearLayout linear = (LinearLayout) findViewById (R.id.linear);
    linear.addView(adView);
    adView.loadAd(new AdRequest());
    adView.setAdListener(this);
 }

public void onDismissScreen(Ad arg0) {
    adView.stopLoading();
            linear.setVisibility(View.GONE);//if you want hide ads
}
}
4

1 に答える 1

0

代わりにこれを試してください:

    adView = new AdView(this, AdSize.BANNER, "a14ebbcd3aae1ff");

adViewフィールドを初期化する代わりに、ローカルのadViewオブジェクトを作成しました。その結果、stopLoading()を呼び出そうとしたときに、adViewがnullになりました。

于 2011-11-10T20:55:23.463 に答える