Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Methods and Exceptions

  1. #1
    Junior Member
    Join Date
    Mar 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default [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).

    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.

    public static void main () throws IOException {

    Should be:

    public static void main (String str []) throws IOException {
    Last edited by Mandraix; March 27th, 2011 at 08:19 PM. Reason: Solved.


  2. #2
    Member vanDarg's Avatar
    Join Date
    Jan 2011
    Location
    Chicago
    Posts
    65
    My Mood
    Mellow
    Thanks
    1
    Thanked 7 Times in 7 Posts

    Default 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.
    "Everything should be made as simple as possible, but not simpler."
    Asking Questions for Dummies | The Java Tutorials | Java Coding Styling Guide

Similar Threads

  1. Use of Exceptions and Methods of The String Class
    By cagataylina in forum Exceptions
    Replies: 1
    Last Post: April 26th, 2011, 02:56 AM
  2. how to handle many more exceptions
    By shailaja in forum Member Introductions
    Replies: 1
    Last Post: December 27th, 2010, 01:02 AM
  3. Prepared Statement exceptions please help
    By nrao in forum What's Wrong With My Code?
    Replies: 5
    Last Post: November 11th, 2010, 08:16 PM
  4. How To add my own Exceptions
    By Newtojava in forum Object Oriented Programming
    Replies: 1
    Last Post: September 2nd, 2010, 08:43 AM
  5. Java Exceptions
    By Vinceisg0d in forum Java Theory & Questions
    Replies: 2
    Last Post: March 13th, 2010, 12:25 AM

Tags for this Thread