简体   繁体   English

为什么要使用setContentView(R.layout.activity_main); 布局错误

[英]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 我正在尝试在我的phonegap应用程序中添加新的admob,并按照admob文档中的步骤进行操作,但是我在此行遇到错误

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

Please help me for remove error from above line 请帮我从上面的行中删除错误

You have not imported R.java . 您尚未导入R.java Add the statement import com.test.demo.R; 添加语句import com.test.demo.R; in the list of your imports. 在您的进口清单中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM