I’m trying to add Buttons dynamically and these in a row.  

In the summary of my code below I have this error: 

```
java.lang.String cannot be cast to android.widget.Button

```

I have been searching in similar error messages, but I can’t solve mine.  

Here is my code:

```
for (int i = 1; i < 5; i++) {
   a=a+a;
  FrameLayout.LayoutParams a = new FrameLayout.LayoutParams(262, 146);
  a.leftMargin = coorX; coorX = coorX + 250; 
  FrameLayout layout = (FrameLayout) findViewById(R.id.layout1);
  layout.addView (((Button)boton.get(i)),a); // here's the error
  ((Button)boton.get(i)).setOnClickListener(new View.OnClickListener(){
       @Override
       public void onClick(View view) {
          switch (((Button)view).getId()){
             case 1: recuadro("wǒ", 1); break;
             case 2: recuadro("hěn", 2); break;
             case 3: recuadro("ne", 3); break;
             case 4: recuadro("nĭ ne?", 4); break;
             case 5: recuadro("yě", 5); break;
          }
  });

}

```