In my main activity I've got error: "cannot resolve symbol "ToastAdListener". Everything is declared in my AndroidManifest.xml and Play Services ara added to libs. Could You tell me what is wrong?

PS. android.widget.Toast is imported too.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    initialize();

    mAdView = new AdView(this);
    mAdView.setAdUnitId(getResources().getString(R.string.ad_unit_id));
    mAdView.setAdSize(AdSize.BANNER);
    mAdView.setAdListener(new ToastAdListener(this)); //here is error
    RelativeLayout layout = (RelativeLayout) findViewById(R.id.relLayout);
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    layout.addView(mAdView, params);
    mAdView.loadAd(new AdRequest.Builder().build());
}
有帮助吗?

解决方案

You need to create or import the ToastAdListsner class wherever you go it from. NB ToastAdListener is NOT an Admob class.

At a guess I'd say you have copied the code above from somewhere. Go back to that source and find the ToastAdListener class. Or implement you own AdListener. Or don't use an AdListener at all. It depends on your use case.

其他提示

Been there, done that... I was lazy too :-)

Look in the package GoogleAdsSampleActivity and find 'ToastAdListener.java'. Select the file, Copy and Paste it into your project package. Done.

Or, just replace ToastAdListener with AdListener, as you will when you publish your real app. ToastAdListener displays Toasts for various AdListener events which are useful only while learning about AdMob.

    mAdView.setAdListener(new AdListener() { // no overrides
    });
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top