当我运行它时,它表示无法解析adView。但我导入了它。这是为什么?
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();
}
});
}
在我的app gradle中,我编译了'com.google.android.gms:play-services-ads:10.2.4'
非常感谢!
答案 0 :(得分:0)
我刚解决了这个问题!我不小心将我的横幅广告ID大写,因此它是@ id / AdView而非@id / adView