java – when does my for statement not run through-ThrowExceptions

Exception or error:

Im trying to set up a way to make sure EditText’s and Radio groups are filled out. I have set up a boolean to say if it’s true or false that something is missing.

For some reason it’s not running past my System.out.println(test0.2) and then starts printing again on System.out.println(isEmpty). The scanState is an enum that will be in the code below.

public enum ScanState {
    scanning,
    empty,
    stopped
}

ScanState scanState;

public boolean checkForms() {
    boolean isEmpty = false;
    scanState = ScanState.scanning;
    ScrollView scrollView = findViewById(R.id.scroll);
    LinearLayout linearLayout = findViewById(R.id.linearLayout);
    final int childCount = linearLayout.getChildCount();
    View element = null;
    for (int i = 0; i < childCount; i++) {
        element = linearLayout.getChildAt(i);
        System.out.println(i);
        switch (scanState) {
            case scanning:
                System.out.println("test0.2");
                if (element instanceof EditText) {
                    System.out.println("test0.3");
                    EditText editText = (EditText) element;
                    if (editText.getText() == null) {
                        scrollView.scrollTo(0, editText.getTop() + 10);
                        isEmpty = true;
                        scanState = ScanState.empty;
                        break;
                    }
                    else {
                        break;
                    }
                }

                if (element instanceof RadioGroup) {
                    RadioGroup radioGroup = (RadioGroup) element;
                    System.out.println("test1");
                    if (radioGroup.getCheckedRadioButtonId() == -1) {
                        System.out.println("test2");
                        scrollView.scrollTo(0, radioGroup.getTop());
                        isEmpty = true;
                        scanState = ScanState.empty;
                        break;
                    } else {
                        break;
                    }

                }
                scanState = ScanState.stopped;
                break;
            case empty:
                break;
            case stopped:
                break;
        }
    }
    System.out.println(isEmpty);
    return isEmpty;
}
How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *