Android/Java question. How are these two decision trees different?
<p>I'm very confused as to how these two decision trees are different. I'm building an app that needs to decide which view to load based on the position selected from a ListView. I've tried to build the logic into a single controller module and found that the switch-case will cause a NullPointerException and FC while the if-else will work perfectly. Can anyone enlighten me as to why? I've got a strong background in C and C++ and am used to being able to easily re-write switches to if-else's and vice versa.</p>

<p>Defined vars:</p>

<pre><code>private final int VALUEA = 0;
private final int VALUEB = 1;
private final int VALUEC = 2;
</code></pre>

<p>Switch-case:</p>

<pre><code>TextView t = new TextView(null);
switch(value){
   case VALUEA:
        setContentView(R.layout.valuealayout);
        t = (TextView) findViewById(R.id.valuealayout);
        t.findViewById(R.id.valuealayout);
   break;
   case VALUEB:
        setContentView(R.layout.valueblayout);
        t = (TextView) findViewById(R.id.valueblayout);
        t.findViewById(R.id.valueblayout);
   break;
   case VALUEC:
        setContentView(R.layout.valueclayout);
        t = (TextView) findViewById(R.id.valueclayout);
        t.findViewById(R.id.valueclayout);
   break;
   default:
   break;
}
</code></pre>

<p>The block above will cause a NullPointerException.</p>

<p>If-else:</p>

<pre><code>if(value == VALUEA ){
   setContentView(R.layout.valuealayout);
   TextView t = (TextView) findViewById(R.id.valuealayout);
   t.findViewById(R.id.valuealayout);
}else if(value == VALUEB){

   setContentView(R.layout.valueblayout);
   TextView t = (TextView) findViewById(R.id.valueblayout);
   t.findViewById(R.id.valueblayout);
}else if(value == VALUEC){
   setContentView(R.layout.valueclayout);
   TextView t = (TextView) findViewById(R.id.valueclayout);
   t.findViewById(R.id.valueclayout);
}else{
}
</code></pre>

<p>This version works perfectly. Does the second block work because of some funky Java scoping rule that allows each branch of the decision tree to create and properly initialize the TextView in a way that the first block doesn't?</p>
