ViewPostIme pointer 1/0

Solution 1:

You shouldn't create the OnItemSelectedListener inside the OnClickListener for your sign in button, instead you have to create it outside and save the selected option in a variable.

Then when the user clicks your sign in button, you check witch option was selected and start the correct Activity.

Looking at your code, you could simply save the intent to the next activity, and when the user clicks the button just start the Activity on that intent.

I've put a check for nullity before trying to start that intent, and you could show the user some dialog or Toast if no valid option was selected.

public class SignInActivity extends Activity {

    private Button bSignup;
    private EditText etNume, etPrenume, etUsername, etPassword, etConfirmPass, etEmail;
    private RadioButton rbMasc, rbFem;
    private Spinner spTipUtilizator, spgrupa, spdept;
    private ProgressBar progBar;
    private Calendar calendar;
    private int year, month, day, currentYear, defday, defmonth, defyear;
    private List<String> tipUtilizatorList, grupaList;
    private ArrayAdapter<String> spinnerArrayAdapterTipU;
    private String nume,prenume,username,password,password2,email,masc,fem,sex,tipUser,dept,DataN;
    private int grupa;

    private Intent activityToStart;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sign_in);

        calendar=Calendar.getInstance();
        calendar.set(1990,12,12);

        bSignup = findViewById(R.id.buttonSignin);
        etNume=findViewById(R.id.et_nume);
        etPrenume=findViewById(R.id.et_prenume);
        etUsername=findViewById(R.id.et_username);
        etPassword=findViewById(R.id.et_password);
        etConfirmPass = findViewById(R.id.et_confirmpassword);
        etEmail=findViewById(R.id.et_email);
        rbMasc=findViewById(R.id.radioButtonMasc);
        rbFem=findViewById(R.id.radioButtonFem);
        spTipUtilizator=findViewById(R.id.spinnerTipUtilizator);
        spgrupa=findViewById(R.id.spinnerGrupa);
        spdept=findViewById(R.id.spinnerDepartament);

        progBar = findViewById(R.id.progressBar);

        tipUtilizatorList=new ArrayList<>(Arrays.asList(getResources().getStringArray((R.array.tipUtilizator))));
        ArrayAdapter<String> adapter=new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,tipUtilizatorList);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spTipUtilizator.setAdapter(adapter);

        grupaList = new ArrayList<>(Arrays.asList(getResources().getStringArray(R.array.grupa)));


        bSignup.setOnClickListener(v -> {
            nume = etNume.getText().toString().trim();
            prenume = etPrenume.getText().toString().trim();
            username = etUsername.getText().toString().trim();
            password = etPassword.getText().toString().trim();
            password2 = etConfirmPass.getText().toString().trim();
            email = etEmail.getText().toString().trim();
            masc = rbMasc.getText().toString().trim();
            fem = rbFem.getText().toString().trim();
            sex=fem;
            tipUser = spTipUtilizator.getSelectedItem().toString().trim();
            grupa = Integer.parseInt(spgrupa.getSelectedItem().toString().trim());
            dept = spdept.getSelectedItem().toString().trim();
            DataN = day+"/"+month+"/"+year;

            progBar.setVisibility(View.VISIBLE);

            if(rbFem.isChecked()) {
                sex=fem;
            }
            else if(rbMasc.isChecked()) {
                sex=masc;
            }

            if(activityToStart != null)
                startActivity(activityToStart);

        });

        spTipUtilizator.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                String Text = parent.getSelectedItem().toString();
                if(Text.equals("Profesor")) {
                    spgrupa.getSelectedView().setEnabled(false);
                    spdept.getSelectedView().setEnabled(true);

                    activityToStart = new Intent(getApplicationContext(),StartProfesorActivity.class);
                    Profesor prof = new Profesor(nume,prenume,username,password,email,sex,dept,DataN);
                    activityToStart.putExtra("profesor",prof);
                    return;
                }
                else if(Text.equals("Student")) {
                    spgrupa.getSelectedView().setEnabled(true);
                    spdept.getSelectedView().setEnabled(false);

                    activityToStart = new Intent(getApplicationContext(),StartStudentActivity.class);
                    Student stud = new Student(nume,prenume,username,password,email,sex,grupa, DataN);
                    activityToStart.putExtra("student",stud);
                    return;
                }

            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });
    }
}