我不知道如何让它在我的游戏中工作…
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
glView = new 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());
}这给了我一个空指针异常,我不知道还能用它做什么。我只是需要知道如何让它与我编程的方式一起工作。我不使用任何XML。
此外,"newID“值变为-1,因此这就是错误的来源
任何帮助我们都将不胜感激。
谢谢
发布于 2011-08-23 16:31:52
尝尝这个,
您没有使用XML,所以这意味着您的视图不是静态创建的( xml),而是动态( java)创建的。
动态创建的视图还没有与之关联的id,所以必须显式设置一个。
view.setId(1)**//choose a non negative integerhttps://stackoverflow.com/questions/6975681
复制相似问题