Nullpointer exception to a dialog object
<p>I received an error from an app on the market to a TextView in a dialog. The error is</p>

<pre><code>java.lang.NullPointerException
at com.b2creativedesigns.eyetest.ColorBlindTest1$2.onClick(ColorBlindTest1.java:324)
</code></pre>

<p>Partial code is:</p>

<pre><code>btnNext1.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {


GlobalVars.setPoints(points);
dialog = new Dialog(ColorBlindTest1.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.cbtdialog);

TextView dialogtext = (TextView) dialog.findViewById (R.id.tvCBTresult); 
TextView dialogtext2 = (TextView) dialog.findViewById (R.id.tvCBTresult2); 
Button btnQuit = (Button) dialog.findViewById (R.id.btnCTBback);  
Button btnFB = (Button) dialog.findViewById (R.id.btnCBTFB); 
Button btnMarket = (Button) dialog.findViewById (R.id.btnCBTMarket); 
if (points &gt;= 14)
{
   dialogtext.setText("Your result is " + points + "/15!");
   dialogtext.setTextColor(Color.rgb(19, 20, 111));
   dialogtext2.setText("Something"); //error line
}
...
</code></pre>

<p>My questions are</p>

<ol>
<li><p>Is it okay to the declare the objects (in case the TextView) here, locally, and not globally outside <code>TextView dialogtext2;</code> and write here only <code>dialogtext2 = (TextView) dialog.findViewById (R.id.tvCBTresult2);</code> <code>?</code></p></li>
<li><p>I have 4 folders for 4 density: layout-ldpi, layout-mdpi, layout-hdpi, layout-xhdpi. The xml in the layout-xhdpi folder did not include the dialogtext2 TextView. Could this cause the error? Doesn't android apply an xml from another density folder when an object is missing from the same xml in another density folder?</p></li>
</ol>

<p>What else can be the root of error?</p>
