简体   繁体   中英

Builder() says cannot resolve symbol on Gradle

I am trying to add an ad to my application and I get the error when I write this code :

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.TextView;

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


public class isPrime extends Activity {

    Button mButton = null;
    TextView resultText = null;
    EditText mInput = null;
    RelativeLayout myLayout = null;
    long input ;
    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

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

ie the error I get is

Builder cannot be resolved into a Symbol

I have read through all the documentation(well at least I think I have.) I am totally new to this field. I would appreciate any help.

Also my XML code is :

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

You are using the wrong import for AdRequest looks like it is looking at the old admob implementation. Use --

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

instead of

import com.google.ads.AdRequest;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM