[SOLVED] Methods and Exceptions
I'm working on a program that will do a number of things, the exact function being performed is selected by the user in a menu. (They type in the number corresponding to their choice, a switch statement calls a method to perform said function)
I'm having trouble with the code in regards to the error-handling (I think).
Code Java:
import java.io.*;
import java.util.*;
class GuildDKP {
public static void menu () throws IOException {
BufferedReader input = new BufferedReader (new InputStreamReader (System.in));
int menuChoice;
int menuFlag = 0;
System.out.println("Please enter the number corresponding to your menu selection:");
System.out.println("1.) Create a new character file.");
System.out.println("2.) Input new DKP/EPGP values.");
System.out.println("3.) Delete existing files.");
System.out.println("4.) Decay existing values.");
System.out.println("5.) Display the current priority list.");
System.out.println("6.) Backup existing files.");
System.out.println("7.) Populate files with random values.");
System.out.println("8.) Clear files of all existing values.");
System.out.println("9.) Exit.\n");
while(menuFlag != 1) {
menuChoice = Integer.parseInt(input.readLine());
switch(menuChoice) {
case 1:
menuFlag++;
break;
case 2:
menuFlag++;
break;
case 3:
menuFlag++;
break;
case 4:
menuFlag++;
break;
case 5:
menuFlag++;
break;
case 6:
menuFlag++;
break;
case 7:
menuFlag++;
break;
case 8:
menuFlag++;
break;
case 9:
System.exit(0);
break;
default:
System.out.println("Incorrect input.");
break;
} // Case
} // While
} // Method: Menu
public static void main () throws IOException {
System.out.println("Welcome to the GuildDKP program!\n");
menu();
} // Method: Main
} // Class: GuildDKP
The above code returns the following run-time error:
Exception in thread "main" java.lang.NoSuchMethodError: main
EDIT: I just went full retard all over the place. If anyone else happens to make such a stupid blunder, I'll put the obvious solution in for future reference.
Code :
public static void main () throws IOException {
Should be:
Code :
public static void main (String str []) throws IOException {
Re: Methods and Exceptions
If you want user input via a console, use a scanner. The BufferedReader is for reading in the contents of a file.