title: Attempt to write to null Array error when passing data to main activity
body: <p>I am still a beginner and this is my first post here on the forum, sorry if the format of the question is not the right one.
  I have an array of Resources in a class called DatabaseTagWalk that I use to find the id of a button in the MainActivity class. </p>
  
  <p>This is the class where I store the id (in the activity_main.xml file i have created 6 buttons and assigned to them the same names as down here</p>
  
  <pre><code>public class DatabaseTagWalk {
  
      int[] iconWalkId;
  
      public DatabaseTagWalk(){
  
          iconWalkId = new int[6];
  
          iconWalkId[0] = R.id.topsightswalk;
          iconWalkId[1] = R.id.literarypariswalk;
          iconWalkId[2] = R.id.secretpassageswalk;
          iconWalkId[3] = R.id.picnictimewalk;
          iconWalkId[4] = R.id.joggitwalk;
          iconWalkId[5] = R.id.deluxegardenswalk;
      }
  }
  </code></pre>
  
  <p>And this is the main activity class where I look for the id of the button to set a specific text and to specify the parameters used when the button is clicked</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
      DatabaseWalks listofwalks;
      DatabaseTagWalk tagWalk;
      Button[] buttons;
      int buttonClicked;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          listofwalks = new DatabaseWalks();
          tagWalk = new DatabaseTagWalk();
  
          for (int i = 0; i &lt; listofwalks.walkList.length; i++) {
  
              buttons[i] = (Button) findViewById(tagWalk.iconWalkId[i]);
              buttons[i].setText(listofwalks.walkList[i].returnWalk());
              setOnClick(buttons[i], tagWalk.iconWalkId[i]);
          }
      }
  
      public void setOnClick(Button button, final int buttonTag ){
          button.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  buttonClicked = buttonTag;
                  Intent startingGame = new Intent("android.intent.action.SECONDACTIVITY");
                  startingGame.putExtra("buttonTag", buttonClicked);
                  startActivity(startingGame);
              }
          });
      }
  }
  </code></pre>
  
  <p>When i run the app I get the error:</p>
  
  <p>"Attempt to write to null array" in the MainActivity at the line:</p>
  
  <pre><code>buttons[i] = (Button) findViewById(tagWalk.iconWalkId[i]);
  </code></pre>