Using variables between if/else in Android
<p>I am developing a small app while learning Android.</p>

<p>The app is basically making a series of simple math calculations. A button is calling a function where the calculations take place. Everything was working fine, until I inserted an if/else construct.</p>

<p>Inside this construct, I am using variables created before, making calculation and setting other variables with this</p>

<pre><code>if (TS&gt;Ex) {
    Double AE = 0.00;
} else {
    Double AE = (Ex-TS);
};

Double TBTAT = (TS-Ex);
Double Exx = 2864.17;   
if (TBTAT&gt;Exx) {
    Double TAT = (Exx*0.2);
} else {
    Double TAT = (TBTAT*0.2);
};
</code></pre>

<p>I have two of these if/else structures.</p>

<p>Then everything is collected and sent to a Text</p>

<pre><code>IT_ResultTXT.setText(Double.toString(AE+TAT+TAF));
</code></pre>

<p>In normal conditions, AE, TAT, TAF turn out to "cannot be resolved to a variable" in this last line of the code, but if I declare them at the beginning of the function, I have an error of duplicated variables.</p>

<p>I suppose is a very stupid basic Java programming error, but I cannot find a solution to this.</p>
