Select an option; (1) Program, (2) Picture or (3) Book
This is returned to the user interface as a string.
private String process_And_Display_Options(String theInput) {
String theOutput;
int fileArrayIndex;
FileConfiguration fc = new FileConfiguration();
// Create Int from selected option
int selection = Integer.parseInt(theInput);
switch (selection) {
case 1:
fileArrayIndex = 0;
get_And_Display_Download_Info();
theOutput = fc.fileDescription[fileArrayIndex] + CONTINUE_OPTIONS;
state = State.Another;
break;
case 2:
fileArrayIndex = 1;
get_And_Display_Download_Info();
theOutput = fc.fileDescription[fileArrayIndex] + CONTINUE_OPTIONS;
state = State.Another;
break;
case 3:
fileArrayIndex = 2;
get_And_Display_Download_Info();
theOutput = fc.fileDescription[fileArrayIndex] + CONTINUE_OPTIONS;
state = State.Another;
break;
default:
theOutput = INVALID_CHOICE + fc.fileOptionsArrayToString();
state = State.Selecting;
break;
}
return theOutput;
}
If a user types in a number that doesn't match 1, 2 or 3 the default case returns an error message and prompts the user to try again.
However, if a user types in a character, the application causes an exception and crashes. I'd imagine this is because I am trying to turn a character into a String which isn't going to go down well. Any ideas how I can ensure that the default case is reached if the user enters a character?
Thanks in advance

New Topic/Question
Reply



MultiQuote




|