I dont know how to get this to working within my game...
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
glView = n开发者_运维知识库ew GLSurfaceView(this);
glView.setRenderer(this);
setContentView(glView);
int newID = glView.getId();
// Create the adView
AdView adView = new AdView(this, AdSize.BANNER, "a14e3ef0948eb58");
// Lookup your LinearLayout assuming it’s been given
// the attribute android:id="@+id/mainLayout"
LinearLayout layout = (LinearLayout)findViewById(newID);
// Add the adView to it
layout.addView(adView);
Initiate a generic request to load it with an ad
adView.loadAd(new AdRequest());
}
This gives me a Null Pointer Exception and I cant figure out what else to do with this. Im just needing to know how to get this to work with the way I have programed this. I dont use any XML.
Also the "newID" value become -1 so thats where the error is coming from
Any help will be appreciated
Thanks
Try this,
You don't use XML so that means your view isn't created static(in xml) but dynamic(in java).
Dynamically created views don't have a id already associated with them yet, so you must set one explicitly.
view.setId(1)**//choose a non negative integer
Check this out: Get ID for views that are added dynamically
精彩评论