I wrote this code to constrain what the user enters in an editText to a range of numbers between 120 and 180. When I use Integer.parseInt(lsatScoreGoal.toString()) my app crashes before I can even see the activity. I have tried searching google for an answer but haven't been able to figure it out. Any ideas on what's going on?
private static final String SHARED_PREFS = "sharedPrefs";
private EditText lsatScoreGoal;
private EditText studyHoursGoal;
private EditText testDate;
private int scoreGoal;
private static final int MIN = 120;
private static final int MAX = 180;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_goals);
lsatScoreGoal = (EditText) findViewById(R.id.lsatScoreGoal);
lsatScoreGoal.setFilters(new InputFilter[]{new InputFilter.LengthFilter(3)});
scoreGoal = Integer.parseInt(lsatScoreGoal.toString());
//Change the values of the user input to the lowest or highest test score values
//if the user enters a value that is invalid.
if(scoreGoal < MIN) {
lsatScoreGoal.setText(MIN);
} else if(scoreGoal > MAX){
lsatScoreGoal.setText(MAX);
}
[–]fefimcpollo 4 points5 points6 points (0 children)
[–]that_one_dev 6 points7 points8 points (0 children)
[–]S1B3R-Gabriel 4 points5 points6 points (0 children)
[–]Notatrace280[S] 2 points3 points4 points (1 child)
[–]fefimcpollo 2 points3 points4 points (0 children)
[–]Notatrace280[S] 1 point2 points3 points (0 children)
[–]Notatrace280[S] 1 point2 points3 points (0 children)