2011-08-07 45 views
0

我不知道如何得到這個我遊戲中的工作...AdMod&GLSurfaceView

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所以多數民衆贊成在錯誤是來自

未來的任何幫助將不勝感激

感謝

回答

0

試試這個,

你不使用XML,這意味着您的視圖不是靜態創建的(使用xml),而是使用動態(在java中)。
動態創建視圖不要有一個id已經與他們關聯,所以你必須明確地設置一個。

view.setId(1)**//choose a non negative integer 


檢查了這一點:Get ID for views that are added dynamically