onClick method execution error while trying to get calculation result from a class to Main Activity onclick method to set a textfield

  android-studio, class, fatal-error, methods, onclick

I have tried to create a class that make a specific calculation. The variables shall be taken from Main Activity and result shall be taken from class and a text field shall be set by an on-click method in Main Activity. However from the error message I understand that app is crashed because on-click method can not be executed resulting from an internal call. I have tried couple of changes in my code but I am still not able to over come this error.

Main Activity code is:

    //Viewprotlara atıyorum
    pressure = findViewById(R.id.pressure);
    designPressureS = String.valueOf(pressure);

    corrosionAllowance = findViewById(R.id.corrosionAllowance);
    corrosionAllowanceS = String.valueOf(corrosionAllowance);

    allowableStress = findViewById(R.id.allowableStress);
    allowableStressS = String.valueOf(allowableStress);

    materialDiameter = findViewById(R.id.materialDiameter);
    materialDiameterS = String.valueOf(materialDiameter);

    materialThickness = findViewById(R.id.materialThickness);
    materialThicknessS = String.valueOf(materialThickness);

    jointFactor = findViewById(R.id.jointFactor);
    jointFactorS = String.valueOf(jointFactor);

    result = findViewById(R.id.result);

    shell = new Shell(allowableStressS,materialDiameterS,materialThicknessS,jointFactorS,designPressureS,corrosionAllowanceS);


}

public void calculation(View view){

    String resultS = String.format("%.2f",shell.thickness());
    result.setText(resultS);

}

}
And this the class:

public class Shell {

String materialSMYS, outerDiameter, materialThickness, jointFactor, pressure, corrosionAllowance;
double designPressureD, corrosionAllowanceD, allowableStressD, materialDiameterD, materialThicknessD, jointFactorD, result;

public Shell(String materialSMYS, String outerDiameter, String materialThickness, String jointFactor, String pressure, String corrosionAllowance){

this.materialSMYS = materialSMYS;
this.outerDiameter = outerDiameter;
this.materialThickness = materialThickness;
this.jointFactor = jointFactor;
this.pressure = pressure;
this.corrosionAllowance = corrosionAllowance;

}

public double thickness(){

designPressureD = Double.parseDouble(pressure);
corrosionAllowanceD = Double.parseDouble(corrosionAllowance);
allowableStressD = Double.parseDouble(materialSMYS);
materialDiameterD = Double.parseDouble(outerDiameter);
materialThicknessD = Double.parseDouble(materialThickness);
jointFactorD = Double.parseDouble(jointFactor);

result = this.designPressureD*this.materialDiameterD/ (this.allowableStressD*this.jointFactorD - 0.6*designPressureD);

return result;

}
}

Source: Android Studio Questions

LEAVE A COMMENT