error: cannot find symbol variable adView

When I run it, it says that it cannot resolve for adView. But I imported it. Why is this?

Nessecary MainActivity.Java:

package stephenshettler.apps.com.coinflip;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.DecelerateInterpolator;
import android.widget.Button;
import android.widget.ImageView;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.AdView;

import java.util.Random;

public class MainActivity extends AppCompatActivity {

private AdView mAdView;

public static final Random RANDOM = new Random();
private ImageView coin;
private Button btn;

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

    // Sample AdMob app ID: ca-app-pub-3940256099942544~3347511713
    MobileAds.initialize(this, "ca-app-pub-8269050231653041~4290758413");


    mAdView = (AdView) findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder().build();
    mAdView.loadAd(adRequest);

    coin = (ImageView) findViewById(R.id.coin);
    btn = (Button) findViewById(R.id.btn);
    btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            flipCoin();
        }
    });


}

In my app gradle, I compile 'com.google.android.gms:play-services-ads:10.2.4'

Thanks so much!

1 answer

  • answered 2017-06-17 19:11 Stephen Shettler

    I just solved the problem! I accidentally capitalized my banner ad id so it was @id/AdView instead of @id/adView