简体   繁体   中英

Why setContentView(R.layout.activity_main); giving error in layout

I'm trying to add new admob in my phonegap application and follow step from admob doc but i get error on this line

setContentView(R.layout.activity_main);   // error in layout

and

LinearLayout layout = (LinearLayout) findViewById(R.id.linearLayout);   // error on linearLayout

Please help me for remove error from these line

main xml file:

    package com.test.demo;
    import android.os.Bundle;
    import org.apache.cordova.*;
    import com.google.android.gms.ads.AdRequest;
    import com.google.android.gms.ads.AdSize;
    import com.google.android.gms.ads.AdView;
    import android.app.Activity;
    import android.os.Bundle;
    import android.widget.LinearLayout;

    public class SecureNotes extends CordovaActivity 
    {
 private AdView adView;
     private static final String AD_UNIT_ID = "AD_UNIT_ID";

@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    super.init();
    super.loadUrl(Config.getStartUrl());
    setContentView(R.layout.activity_main);
    adView = new AdView(this);
    adView.setAdSize(AdSize.BANNER);
    adView.setAdUnitId(AD_UNIT_ID);
    LinearLayout layout = (LinearLayout) findViewById(R.id.linearLayout);
    layout.addView(adView);
  device ID to
    AdRequest adRequest = new AdRequest.Builder()
        //.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
        //.addTestDevice("INSERT_YOUR_HASHED_DEVICE_ID_HERE")
        .build();
    adView.loadAd(adRequest);
  }
  @Override
  public void onResume() {
    super.onResume();
    if (adView != null) {
      adView.resume();
    }
  }

  @Override
  public void onPause() {
    if (adView != null) {
      adView.pause();
    }
    super.onPause();
  }
  @Override
  public void onDestroy() {
    // Destroy the AdView.
    if (adView != null) {
      adView.destroy();
    }
    super.onDestroy();
  }
}

Please help me for remove error from above line

You have not imported R.java . Add the statement import com.test.demo.R; in the list of your imports.

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