2011-11-10 3 views
0

사용자가 adview를 클릭 한 후 광고로드를 중지하고 싶습니다. 이미 adlistener를 구현했으며 adView.stopLoading();클릭 후 admob 광고 로딩 중지

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 
} 
} 

답변

0

그냥이 대신보십시오 :

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

당신은 로컬 같이 adView를 만들어 내가 광고 웹 페이지를 닫을 때 onDismissScreen에 있지만, 나는 다음과 같은 오류가 발생합니다 개체를 사용하여 adView 필드를 초기화 할 필요가 없습니다. 따라서 stopLoading()을 호출 할 때 adView가 null입니다.

+0

이 작동하지 않지만 오류는 다시 발생하지 않지만 adview는 광고를로드하는 데 아무런 문제가 없습니다. 또한 linear.removeView (adView)를 추가하면; 이전과 같은 오류가 발생했습니다. – user1001635

+0

광고를 더 이상 새로 고치지 않고 계속 표시하고 싶습니까? stopLoading은 이미 해당 프로세스를 시작한 경우 광고로드를 중지하지만 stopLoading은 삽입 광고에 더 유용하다고 생각합니다. 'linear' 에러에 관해서는 선형 필드를 초기화하는 대신에 지역 선형 객체를 정의하는 것과 같은 실수를 저지르고 있습니다. –

+0

지금 작동 :) thks eric – user1001635