AdRequest Builder 无法解析为类型
AdRequest Builder cannot be resolved to a type
我在 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 使用略微修改的框架版本为 Android 开发了一款游戏,并成功添加了广告,但没有在我的主 activity 上添加广告,因为该框架没有有一个 .xml 主文件 activity(纯 java 代码的表面视图)。但是,我也希望广告出现在主要 activity 上,因为它包含 95% 的游戏内容。我使用在线教程成功地在 surfaceview 上添加了一个测试视图(按钮),但是当我将按钮更改为 AdView 时,出现了这个错误:
"AdRequest.Builder cannot be resolved to a type" 在
AdRequest adRequest = new AdRequest.Builder().build();
.
谁能告诉我是什么导致了这个错误? Eclipse 在同一项目的另一个 activity 中接受了完全相同的代码,但不在此处。我已经进行了必要的导入。
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);
}
感谢任何帮助。
使用这个import com.google.android.gms.ads.AdRequest;
使用这个库
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.AdRequest;
我在 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 使用略微修改的框架版本为 Android 开发了一款游戏,并成功添加了广告,但没有在我的主 activity 上添加广告,因为该框架没有有一个 .xml 主文件 activity(纯 java 代码的表面视图)。但是,我也希望广告出现在主要 activity 上,因为它包含 95% 的游戏内容。我使用在线教程成功地在 surfaceview 上添加了一个测试视图(按钮),但是当我将按钮更改为 AdView 时,出现了这个错误:
"AdRequest.Builder cannot be resolved to a type" 在
AdRequest adRequest = new AdRequest.Builder().build();
.
谁能告诉我是什么导致了这个错误? Eclipse 在同一项目的另一个 activity 中接受了完全相同的代码,但不在此处。我已经进行了必要的导入。
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);
}
感谢任何帮助。
使用这个import com.google.android.gms.ads.AdRequest;
使用这个库
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.AdRequest;