1

特定の値が返されない場合、残りの onClick メソッドが実行されないようにする必要がある状況があります。

public void onClick(View v) {
    double a = 0;
    double b = 0;
    double c = 0;
    try {
        a = Double.parseDouble(((EditText) getView().findViewById(R.id.area_a)).getText().toString());
        b = Double.parseDouble(((EditText) getView().findViewById(R.id.area_b)).getText().toString());
        c = Double.parseDouble(((EditText) getView().findViewById(R.id.area_c)).getText().toString());
    } catch (NumberFormatException e) {
            //Exception here! Do not continue with the rest of the onClick method!
    }
    ...
}

例外がキャッチされた場合、残りの onClick メソッドをスキップする方法はありますか?

4

1 に答える 1

3

return;catch ブロックを入れてみてください。

于 2012-07-09T01:36:57.327 に答える