AdRequest Builder无法解析为一个类型 [英] AdRequest Builder cannot be resolved to a type

查看:1001
本文介绍了AdRequest Builder无法解析为一个类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开发了一个游戏使用框架略加修改版本的 http://www.kilobolt.com/unit-4-android-game-development.html 。然后,我跟着这个教程: https://developers.google .COM /移动广告的SDK /文档/ AdMob的/安卓/快速启动,并成功添加了一个广告,但不是我的主要业务为这个框架不具备的主要活动一个.xml文件(表面观在纯java code)。不过,我想广告出现在主要活动也因为含有95%的游戏。我设法使用一个在线教程,成功添加一个测试视图(按钮)在surfaceview但是当我改变了按钮的AD浏览报我得到这个错误:

I finished developing a game for Android using a slightly modified version of the framework at http://www.kilobolt.com/unit-4-android-game-development.html. Then I followed this tutorial:https://developers.google.com/mobile-ads-sdk/docs/admob/android/quick-start and successfully added an ad but not on my main activity as this framework does not have a .xml file for the main activity (surface view in pure java code). However, I want ads to appear on the main activity too since that contains 95% of the game. I managed to successfully add a test view (button) on the surfaceview using an online tutorial but when I changed the button to an AdView I got this error:

AdRequest adRequest =新AdRequest.Builder()建();

谁能告诉我,这可能会导致这个错误? Eclipse的接受完全相同的code。在我的其他活动在同一个项目,但不是在这里。我已经做了必要的进口。

Can someone tell me what could cause this error? Eclipse accepted the exact same code in my other activity on the same project but not here. I have made the necessary imports.

import com.google.ads.AdRequest;
import com.google.android.gms.ads.AdView;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    appContext = this.getApplicationContext();
    mainLayout = new FrameLayout(this);
    adLayout = new RelativeLayout(this);

    adView = new AdView(this);
    adView.setAdUnitId("ca-app-pub-3940256099942544/6300978111"); // google test id
    //AdRequest adRequest = new AdRequest.Builder().build();
    adView.setAdSize(AdSize.BANNER);


    RelativeLayout.LayoutParams lp1 = new LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    RelativeLayout.LayoutParams lp2 = new LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
    adLayout.setLayoutParams(lp2);
    adLayout.addView(adView);
    lp1.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);  
    lp1.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
    adView.setLayoutParams(lp1); 

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    boolean isPortrait = getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;
    int frameBufferWidth = isPortrait ? 800 : 1280;
    int frameBufferHeight = isPortrait ? 1280 : 800;
    Bitmap frameBuffer = Bitmap.createBitmap(frameBufferWidth, frameBufferHeight, Config.RGB_565);

    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    float scaleX = (float) frameBufferWidth / metrics.widthPixels;
    float scaleY = (float) frameBufferHeight / metrics.heightPixels;

    GameScreen.deviceWidth = metrics.widthPixels;
    GameScreen.deviceHeight = metrics.heightPixels;

    prefs = this.getSharedPreferences("AppPrefs", Context.MODE_PRIVATE);
    prefsExist = prefs.contains("showValueAddition");
    loadDefaultSettings();

    renderView = new AndroidFastRenderView(this, frameBuffer);
    graphics = new AndroidGraphics(getAssets(), frameBuffer);
    fileIO = new AndroidFileIO(this);
    audio = new AndroidAudio(this);
    input = new AndroidInput(this, renderView, scaleX, scaleY);
    screen = getInitScreen(prefs);

    mainLayout.addView(renderView);
    mainLayout.addView(adLayout);
    setContentView(mainLayout);
}

任何帮助是AP preciated。

Any help is appreciated.

推荐答案

使用该进口com.google.android.gms.ads.AdRequest;

这篇关于AdRequest Builder无法解析为一个类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆