我在跑步时得到FC,但它会编译。
注意:根据Rasel的评论进行了更改。还是FC的
btnExecute.setOnClickListener(new View.OnClickListener() //this worked
{
private AlertDialog show;
public void onClick(View arg0)
{ //start of get stack shape and provide area and equivalent diameter
//20110720
//just trying to evaluate the shape to use the correct inputs for area calculation
//I will then add and evaluate for the units of input to build universal
//values(_eng and _met)variables to use for all further calculations. KISS!
if (((m1_ss_spinner.getSelectedItem().toString().equals("Square")))) //cant compare a string with == operator. Use equals() to compare
{
if ((m1_sqs1.getText().length() == 0) //if m1_sqs1 is empty
|| (m1_sqs1.getText().toString().equals(""))) //if m1_sqs1 is blank
{
show = new AlertDialog.Builder(mContext).setTitle("Error") //this worked
.setMessage("The Square Side length is empty")
.setPositiveButton("OK", null).show();
} else
{
double result = new Double(m1_sqs1.getText().toString()) * new Double(m1_sqs1.getText().toString());
m1_sa_in.setText(Double.toString(result));
} //end of square area
} else
if (((m1_ss_spinner.getSelectedItem().toString().equals("Rectangle"))))
{
if ((m1_rs1.getText().length() == 0)
|| (m1_rs1.getText().toString().equals("")
|| (m1_rs2.getText().length() == 0)
|| (m1_rs2.getText().toString().equals(""))))
{
show = new AlertDialog.Builder(mContext).setTitle("Error")
.setMessage("A Rectangle Side length is empty")
.setPositiveButton("OK", null).show();
} else
{
double result = new Double(m1_rs1.getText().toString()) * new Double(m1_rs2.getText().toString());
m1_sa_in.setText(Double.toString(result));
} //end of rectangle area
} else
if (((m1_ss_spinner.getSelectedItem().toString().equals("Circle"))))
{
if ((m1_cd.getText().length() == 0)
|| (m1_cd.getText().toString().equals("")))
{
show = new AlertDialog.Builder(mContext).setTitle("Error")
.setMessage("The Circle Diameter is empty")
.setPositiveButton("OK", null).show();
} else
{
double result = new Double(m1_cd.getText().toString()) * new Double(m1_cd.getText().toString());
m1_sa_in.setText(Double.toString(result));
} //end of circle area
} else
if (((m1_ss_spinner.getSelectedItem().toString().equals("Elliptical"))))
{
if ((m1_els1.getText().length() == 0)
|| (m1_els1.getText().toString().equals("")
|| (m1_els2.getText().length() == 0)
|| (m1_els2.getText().toString().equals(""))))
{
show = new AlertDialog.Builder(mContext).setTitle("Error")
.setMessage("An Elliptical Diameter is empty")
.setPositiveButton("OK", null).show();
} else
{
double result = new Double(m1_els1.getText().toString()) * new Double(m1_els2.getText().toString());
m1_sa_in.setText(Double.toString(result));
}; //end of elliptical area
} // end of onClick code
}
});
答案 0 :(得分:1)
您无法将字符串与==运算符进行比较。使用equals()方法进行比较。请尝试这样
if (((m1_ss_spinner.getSelectedItem().toString().equals("Square")))) //need to prove this
{
if ((m1_sqs1.getText().length() == 0) //if m1_sqs1 is empty
|| (m1_sqs1.getText().toString().equals(""))) //if m1_sqs1 is blank
答案 1 :(得分:0)
编译似乎只验证代码而不是逻辑。我需要非常小心代码,我现在建议使用大量注释和严格格式的缩进,这样如果语句很容易确定,当程序保留时会发生开始和结束FC决定不能做出