title: I can't change the textview text by pressing a button
body: <p>Hello all I am struggling to change the textview text dynamically in android studio i get 0 errors but when i am testing the program runs but at the time i press the button program crashes</p>
  
  <p>CODE:</p>
  
  <pre><code>public class MyFragment extends Fragment { TextView tv;
  
  Button[] btn = new Button[30];
  TextView tv;
  
  
  
  @Override
  public  View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
      // TODO Auto-generated method stub
  View myFragmentView = inflater.inflate(R.layout.fragmentlayout, container, false);
  tv = (TextView) findViewById(R.id.textView1);
  for (int i = 0; i &lt; 30; i++) {
      btn[i] = new Button(getActivity());
      btn[i].setText("1");
      btn[i].setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, `LayoutParams.WRAP_CONTENT));`
      btn[i].setVisibility(View.VISIBLE);
      btn[i].setId(i);
      linearLayout.addView(btn[i]);
  
  
  
  btn[2].setOnClickListener(btnOnClickListener);
  
  
  Button.OnClickListener btnOnClickListener = new Button.OnClickListener() {
  
  
  
   @Override
      public void onClick(View v) {
          // TODO Auto-generated method stub
  
  
          if (v == btn[2]) {
  
              tv.setText(btn[2].getText());
          }
  
      }
  };
  </code></pre>
  
  <p>This is not the all parts of the code(there are 2 fragments this is one of them) but i can't share all of the program itself, but these are all the parts about my problem. If you have anything to say please say it. Thanks in advance</p>