title: In android how do I add buttons into a TableLayout from an array of buttons programmatically?
body: <p>Am new to android programming, just started learning it the past 6 weeks and am writing a minesweeper game for android, well i've managed to do some part of the game without much issues. However, I've got to design a grid programmatically using TableLayout and TableRow and insert buttons in them; so I've written few lines of code to do that but whenever I run the game i get "Confirm Perspective Switch" error.</p>
  
  <p>Here are the codes I've written - </p>
  
  <pre><code>` public class Game extends Activity implements OnClickListener {
  
          Button[][] btn = new Button[6][6]; 
          public void onCreate(Bundle savedInstanceState){
              super.onCreate(savedInstanceState);
              setContentView(R.layout.gamegrid);
  
              int i, j;
  
              LinearLayout layoutVertical = (LinearLayout) findViewById(R.layout.gamegrid);
              //create a new TableLayout
              TableLayout table = null;
  
              table.setStretchAllColumns(true);  
              table.setShrinkAllColumns(true);
  
              LayoutParams param = new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
  
              for(i = 0; i &lt;6; i++){
                  table = new TableLayout(this);
                  table.setWeightSum(5);
                  layoutVertical.addView(table, param);
                  for(j=0; j&lt;7; j++){
                      btn[i][j] = new Button(this);
                      table.addView(btn[i][j], param);    
                      btn[i][j].setOnClickListener(this);
                      }
              } return;   
          }
          public void onClick(View arg0) {
              // TODO Auto-generated method stub
  
          }
  
      } `
  </code></pre>
  
  <p>I think my problem is with the following lines - </p>
  
  <pre><code>`for(i = 0; i &lt;6; i++){
  table = new TableLayout(this);
      table.setWeightSum(5);
      layoutVertical.addView(table, param);
      for(j=0; j&lt;7; j++){
          btn[i][j] = new Button(this);
          table.addView(btn[i][j], param);
          btn[i][j].setOnClickListener(this);
          }
      }`
  </code></pre>
  
  <p>It's suppose to create buttons then store them in an array of buttons then insert the buttons in the TableLayout!</p>
  
  <p>And why am I getting the above error?</p>
  
  <p>Could you please help me point out what am doing wrong? As I do not have any errors showing.</p>
  
  <p>Thanks</p>