0

i'll get to the point immediately, this is my code:

 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]);
           }

the code works fine without the line rg[i].addView(textView);, but when i put that line the application force closes... What's the problem? How can i put this textview into this group?

4

1 に答える 1

1

あなたがそれを追加しようとしているとき、あなたのtextViewはnullだと思います。完全な logcat トレースを提供できますか。

于 2012-09-22T13:29:00.310 に答える