Reputation: 135
I'm trying to put some ad in my Android app, but I've a problem...
package com.dotgears.flappybird;
import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;
import com.google.ads.*;
public class BannerSample extends Activity {
private AdView adView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Create the adView
adView = new AdView(this, AdSize.BANNER, "...");
// Lookup your LinearLayout assuming it's been given
// the attribute android:id="@+id/mainLayout"
LinearLayout layout = (LinearLayout)findViewById(R.id.linearLayout);
// Add the adView to it
layout.addView(adView);
// Initiate a generic request to load it with an ad
adView.loadAd(new AdRequest());
}
@Override
public void onDestroy() {
if (adView != null) {
adView.destroy();
}
super.onDestroy();
}
}
I followed the Google dev's istructions but on the line adView.loadAd(new AdRequest());
Eclipse says:
The constructor AdRequest() is not visible
Why isn't it visible? I searched everywhere but I didn't find anything.
Upvotes: 4
Views: 3441
Reputation:
simply use the following import
import com.google.android.gms.ads.AdRequest;
also add the lib of google play services
Upvotes: 3
Reputation: 5207
Do it in this way
AdRequest adreq=new AdRequest.Builder().build();
adview.loadAd(adreq);
and it will work. also import it by using
import com.google.android.gms.ads.AdRequest;
and it will start working
Upvotes: 3
Reputation: 139
i was having the same problem. that was because i was using Google Play services and Google Admob together i just removed google play services library and it worked!
Upvotes: 0