I am developing an Android application and don’t know hot to handle null values in calculations in formulas. Here is my code through which I’m trying to skip null value but this is not working.
Update
Actually I am trying to do this
package ecc.ecc.pkg;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import ecc.ecc.pkg.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class ECCActivity extends Activity {
Button btncalc;
EditText molcostper;
TextView costper;
double molcost = 0;
double cstperusd = 0;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
initcontrols();
}
public void initcontrols()
{
molcostper=(EditText)findViewById(R.id.molcostper);
costper=(TextView)findViewById(R.id.costper);
btncalc=(Button)findViewById(R.id.btnCalc);
btncalc.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v)
{
calculate();
}
});
}
public void calculate()
{
NumberFormat formatter = new DecimalFormat("#,###,###,###.##");
molcost=Double.parseDouble(molcostper.getText().toString());
cstperusd = replaceIfNull(molcost,8500)*94
costper.setText(formatter.format(cstperusd));
}
public static <T> T replaceIfNull(T objectToCheck, T defaultValue) {
return objectToCheck==null ? defaultValue : objectToCheck;
}
}
this method is genrating error please any one help to handle this
Try this one.
if it doesn’t work then try to download the ‘/data/anr/traces.txt’ file and check the log. It might provide you some hints. If possible please paste the log here which can help us to identify the problem.