Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AdRequest.Builder cannot be resolved to a type

Tags:

android

admob

I'm incorporating AdMob into my app. I've followed the steps in the developers page. However AdRequest.Builder() is being underlined with red and it says:

AdRequest cannot be resolved to a type

and

AdRequest.Builder cannot be resolved to a type.

What could be the problem?

import com.google.ads.AdRequest;
import com.google.ads.AdView;


public class FireRoomActivity extends Activity {

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

        // Look up the AdView as a resource and load a request.
        AdView adView = (AdView)this.findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder().build();   
        adView.loadAd(adRequest);
    }

In xml I've shown admob as such:

<com.google.android.gms.ads.AdView android:id="@+id/adView"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     ads:adUnitId="bla bla"
                     ads:adSize="BANNER"/>
like image 927
Nazerke Avatar asked Dec 16 '13 09:12

Nazerke


2 Answers

Your code is mix for Admob SDK (Google Play) and Android (6.4.1 and earlier SDKs)

Use

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;

AdRequest adRequest = new AdRequest.Builder().build();

and

<com.google.android.gms.ads.AdView android:id="@+id/adView"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     ads:adUnitId="bla bla"
                     ads:adSize="BANNER"/>

if you use Admob SDK (Google Play)

Or use

import com.google.ads.AdRequest;
import com.google.ads.AdView;

AdRequest adRequest = new AdRequest();

and

<com.google.ads.AdView android:id="@+id/adView"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     ads:adUnitId="bla bla"
                     ads:adSize="BANNER"/>

if you use earlies SDK

For Admob SDK (Google Play) not forget to change namespase

xmlns:ads="http://schemas.android.com/apk/res-auto"
like image 143
itvdonsk Avatar answered Oct 22 '22 07:10

itvdonsk


Try this..

AdRequest adRequest = new AdRequest();   
AdView adView = (AdView)this.findViewById(R.id.adView);           
adView.loadAd(adRequest);

Note:

  1. Make sure you have included the necessary library in your project and permissions in your manifest.

  2. Also check whether you have given correct ad-mob id in your xml.

EDIT :

To add test device, you could try

adRequest.addTestDevice(AdRequest.TEST_EMULATOR);  //for emulators
adRequest.addTestDevice("device_id");              //for real device, enter device id
like image 34
Hariharan Avatar answered Oct 22 '22 08:10

Hariharan