the value is never used although it's used

Saif Ashraf :

I'm getting an error in my code that (the first in the main if and the main if else) value of tn in the if statement is never used, although the other assigned value with above it is okay, and other tn values are okay, and I used tn at the end as in a textview. so the application skips it and uses the next tn value..

String Classification = null;
String tn = null;
if (pi<0){
    pi=0;
}
if (p200<=50){
    if (p4<50) {
        if (p200<5) {
            if (cu>4 && cc<=3 && cc>=1){
                Classification="GW";
                tn = "Well graded gravels, Gravel-Sand mixtures, little or no fines";
                //  ^^^ THIS ONE ^^^

            }
            else
                Classification="GP";
                tn = "Poorly graded gravels, Gravel-Sand mixtures, little or no fines";
        }
        if
        (p200>12){
            if ( (pi<y )|| pi<4){
                Classification="GM";
                tn ="Silty gravels, Poorly graded gravel-sand-silt mixtures";
            }
            if (pi>7 && pi>=y){
                Classification="GC";
                tn ="Clayey gravels, Poorly graded gravel-sand-clay mixtures";

            }
        }
        if (p200>=5 && p200<=12) {
            if (cu>4 && cc<=3 && cc>=1 && (pi<4 || pi<y )) {
                Classification = "GW-GM";
                tn="Well graded silty gravel";
            }
            else if (cu>4 && cc<=3 && cc>=1 && pi>7 &&pi>=y) {
                Classification = "GW-GC";
                tn="Well graded clayey gravel";
            }
            else if (pi<4 || pi<y){
                Classification = "GP-GM";
                tn="Poorly graded silty gravel";
            }
            else if (pi>7 && pi>=y){
                Classification = "GP-GC";
                tn="Poorly graded clayey gravel";
            }
        }
    }
    else if (p4>50){
        if (p200<5){
            if (cu>6 && cc>=1 && cc<=3){
                Classification="SW";
                tn="Well graded sands, gravelly sands, little or no fines";
                //^^^ AND THIS ONE ^^^
            }
            else
                Classification="SP";
                tn ="Poorly graded sands, gravelly sands, little or no fines";
        }
        else if (p200>5){
            if ((pi<y ) || pi<4){
                Classification="SM";
                tn="Silty sands, Poorly graded sand-silt mixtures";
            }
            else if (pi>7 && pi>y){
                Classification="SC";
                tn="Clayey Sands, Poorly graded sand-clay mixtures";
            }
        }
        if (p200>=5 && p200<=12) {
            if (cu>6 && cc<=3 && cc>=1 && (pi<4 || pi<y)) {
                Classification = "SW-SM";
            }
            else if (cu>6 && cc<=3 && cc>=1 && pi>=7) {
                Classification = "SW-SC";
            }
            else if (pi<4 ||pi<y ){
                Classification = "SP-SM";
            }
            else if (pi>7 && pi>y){
                Classification = "SP-SC";
            }
        }

    }

}
else if (p200>50){
    if (ll<50){
        if (pi>7  && pi>y){
            Classification="CL";
            tn ="Inorganic clays of low to medium plasticity, gravelly clays, sandy clays, silty clays, lean clays";
        }
        else if(pi<4){
            Classification="ML";
            tn="Inorganic silts and very fine sands, rock flour, silty or clayey fine sands with slight plasticity";
        }

    }
    else if (ll>50){
        if (pi>y){
            Classification="CH";
            tn="Inorganic clays of high plasticity, fat clays";
        }
        else if (pi<y) {
            Classification="MH";
            tn="Inorganic silts, micaceous or dictomaceous fine sandy or silty soils, elastic silts";
        }

    }
}
if (pi>=4 && pi<=7 && ll>16 &&ll<26 || (ll>26 && ll< 30 && pi>=y&& pi<=7)){
    Classification="CL-ML";
}
if (p4==0 && p200==0){
    Classification=" ";
    tn=" ";
}


if(p200>100 || p4>100 || pi>70) {
    if (p200 > 100)
        editText1.setError("out of range");
    if (p4 > 100)
        editText2.setError("out of range");
    if (pi >= 70)
        editText5.setError("out of range");
}
else {
        result.setText(String.valueOf(Classification));
        typicalname.setText(String.valueOf(tn));
}
Jens :

you miss {} arround your else blocks, so the second line is always executed and overrides the value

if (cu>4 && cc<=3 && cc>=1){
   Classification="GW";
    tn = "Well graded gravels, Gravel-Sand mixtures, little or no fines";
    //  ^^^ THIS ONE ^^^

}
else {
   //^ is missing also on end of this block
    Classification="GP";
    tn = "Poorly graded gravels, Gravel-Sand mixtures, little or no fines";
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=356218&siteId=1