2012-09-22 33 views
0

我馬上切入正題,這是我的代碼:錯誤添加到TextView的RadioGroup中

RadioButton[] rb=new RadioButton[n*3]; 

      RadioGroup[] rg=new RadioGroup[n]; 
      for(int i=0;i<n;i++) 
      { 
       rg[i] = new RadioGroup(MainActivity.this); 
       rg[i].setOrientation(RadioGroup.HORIZONTAL); 
       rg[i].setId(i); 
       //rg[i].addView(textView); doesn't work with this 
       for(int j=0;j<3;j++) 
       { 
        rb[i*3+j]=new RadioButton(MainActivity.this); 
        rb[i*3+j].setId(i*3+j); 
        rb[i*3+j].setText("something"); 
        rg[i].addView(rb[i*3+j]); 
       } 
       myLayout.addView(rg[i]); 
      } 

的代碼工作正常,沒有線路rg[i].addView(textView);,但是當我把該行的應用程序強制關閉.. 。 有什麼問題?我怎樣才能把這個textview放到這個組中?

+0

什麼問題?看看你的logcat。如果你不能解決它,然後在這裏發佈logcat。 –

+0

你在哪裏創建TextView ..你確定textview不爲null – Ronnie

+0

看起來像這樣的問題,我只是再次檢查我的代碼 – Vladimir

回答

1

我認爲你的textView在你試圖添加它時是null的。你能提供完整的logcat跟蹤嗎?