为什么选择setContentView(R.layout.activity_main);在布局中给出错误

时间:2014-05-18 11:16:11

标签: android layout cordova admob

我试图在我的手机屏幕应用程序中添加新的admob并按照admob doc的步骤操作,但我在此行中收到错误

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

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

请帮我删除这些行中的错误

主xml文件:

    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();
  }
}

请帮我从上面删除错误

1 个答案:

答案 0 :(得分:0)

您尚未导入R.java。在导入列表中添加语句import com.test.demo.R;