Admob Android:findViewById未解决

时间:2016-07-08 08:27:27

标签: java android android-studio admob

我无法构建我的项目,因为未解析findViewById。可能有什么不对?可能是因为我在其他文件中遗漏了一些Admob代码?我怎样才能让Admob工作。我尝试清理代码并清除缓存。可能是什么问题?

这是AndroidApplication.java中的代码:

    package io.enormous.avocardo;

    import android.app.Application;
    import com.crashlytics.android.Crashlytics;
    import io.enormous.avocardo.common.analytics.AnswersTracker;
    import io.enormous.avocardo.common.analytics.GoogleAnalyticsTracker;
    import io.enormous.avocardo.common.di.ApplicationComponent;
    import io.enormous.avocardo.common.di.ApplicationModule;
    import io.enormous.avocardo.common.di.DaggerApplicationComponent;
    import io.fabric.sdk.android.Fabric;
    import timber.log.Timber;
    import uk.co.chrisjenx.calligraphy.CalligraphyConfig;
    import com.google.android.gms.ads.AdRequest;
    import com.google.android.gms.ads.AdView;
    import com.google.android.gms.ads.MobileAds;

    public class AndroidApplication extends Application {

    private Mode mode;
    private ApplicationComponent applicationComponent;

    @Override public void onCreate() {
    super.onCreate();
    checkTestMode();
    this.initializeInjector();

    MobileAds.initialize(getApplicationContext(), "ca-app-pub-7014730672857176~3011130441");

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

    }

1 个答案:

答案 0 :(得分:1)

Application没有View,因此您无法在那里找到任何视图。你应该在活动或片段中进行。