title: Programmatically generated text field is not showing up in Android app
body: <p>I'm trying to programmatically generate some UI elements onto an android app with Java. I have a ScrollView created in the XML file, and I'm trying to create and add a bunch of UI elements to that ScrollView. All of the UI elements make up 1 bounding box that looks like this: </p>
  
  <p><img src="https://i.stack.imgur.com/K4Uvx.jpg" alt="http://i.imgur.com/pwI8MNi.jpg"></p>
  
  <p>The bounding box is just a linear layout with an image background, and some text boxes and labels sitting on top of it. I want my code to be modular, so I'm making a class called BoundingBox which should create and add a bounding box to the app every time I instantiate the BoundingBox class. </p>
  
  <p>Here's what I have so far for the BoundingBox class (it's not complete, all it adds so far is a textview with text on it). </p>
  
  <pre><code>public class BoundingBox {
  //Instantiate the main app activity.
  MainActivity theMainActivity = new MainActivity();
  
  //Create Scrollview object and set it to the XML GUI scrollview
  ScrollView sv = (ScrollView) theMainActivity.findViewById(R.id.theMainScrollView);
  
  public BoundingBox(){
  
      //Create linear layout that will sit in the scrollview.
      LinearLayout mainLinearLayout = new LinearLayout(theMainActivity);
  
      TextView exerciseName = new TextView(theMainActivity);
  
      TextView repBox1 = new TextView(theMainActivity);
      TextView repBox2 = new TextView(theMainActivity);
      TextView repBox3 = new TextView(theMainActivity);
      TextView repBox4 = new TextView(theMainActivity);
  
  
      //Add the Linear Layout to the existing scroll view.
  
      sv.addView(mainLinearLayout);
  
      //Add text box to linear layout
      mainLinearLayout.addView(exerciseName);
      exerciseName.setText("This doesn't work.");
  
      }
  }
  </code></pre>
  
  <p>Here's how I instantiate it in my main Activity:</p>
  
  <pre><code>@Override
  public boolean onCreateOptionsMenu(Menu menu) {
      BoundingBox sc = new BoundingBox();
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.menu_main, menu);
  
      return true;
  }
  </code></pre>
  
  <p>The code compiles successfully but no text shows up in my Android app. If I instantiated the class then it should have already ran the code in the BoundingBox constructor, which should have created a text view. I'm not sure what I'm doing wrong, and since the code compiles successfully logcat doesn't tell me anything. If I instantiate the bounding box class in the onCreate() function, the app crashes when starting it. If I instantiate it in the onCreateOptionsMenu function, it runs but it doesn't create a text view. </p>