AdRequest Builder cannot be allowed for type

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

"AdRequest.Builder cannot be allowed for type" in

AdRequest adRequest = new AdRequest.Builder().build(); .

Can someone tell me what might cause this error? Eclipse accepted the same code in my other activity in the same project, but not here. I made the necessary import.

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

Any help is appreciated.

0
source share
2 answers

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

+2
source

Use this library

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

All Articles