为什么这段代码给我一个IllegalStateException?

时间:2016-07-19 19:11:23

标签: android

每当我运行此代码时,第一个editText为空,第二个和第三个带有双精度(与if语句中的条件相同),我得到:

java.lang.IllegalStateException: Could not execute method for android:onClick

这是为什么?以下是我的代码。

public void pytform (View view){
    String pt1_text = pt1.getText().toString().trim();
    double a = Double.parseDouble(pt1_text);
    String pt2_text = pt2.getText().toString().trim();
    double b = Double.parseDouble(pt2_text);
    String pt3_text = pt3.getText().toString().trim();
    double c = Double.parseDouble(pt3_text);


    if(pt1_text.isEmpty() && !pt2_text.isEmpty() && !pt3_text.isEmpty()) {
        a = Math.sqrt(Math.pow(c,2) - Math.pow(b,2));
        pt4.setText("a =: " + a);
    }
    else {
        pt4.setText("Invalid Input");
    }
}

1 个答案:

答案 0 :(得分:0)

试试这个......     if(pt1_text.equals("")&&!pt2_text.equals("")&&!pt3_text.equals()){         a = Math.sqrt(Math.pow(c,2) - Math.pow(b,2));         pt4.setText(" a =:" + a);     }     其他{         pt4.setText("输入无效");     }