Trying to dynamically add a TextView to a ScrollView crashes when using an XML layout
<p>This is a very simple example where I have a single ScrollView defined in R.layout.main.  Then I try to dynamically add a TextView to it.</p>

<p>Unfortunately this crashes.</p>

<pre><code>ScrollView scroll = (ScrollView) this.findViewById(R.id.scrollView1);

TextView tv1 = new TextView(this);
tv1.setText("This is tv1");

scroll.addView(tv1);

setContentView(R.layout.main);
</code></pre>

<p>Now I <em>can</em> do something like this:</p>

<pre><code>ScrollView scroll = new ScrollView(this);
TextView tv1 = new TextView(this);
tv1.setText("This is tv1");

scroll.addView(tv1);

setContentView(scroll);
</code></pre>

<p>But I'd really like to be able to define some base UI elements in XML, then dynamically add others.</p>

<p>What's the best way to do that?</p>
