Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

newbie help - methods and run-time error

807597Oct 30 2005 — edited Oct 31 2005
ok so im following an example in this java book. I typed the code in word for word, it compiles fine, no errors. But when i open dos and run the program i get the error "Exception in thread 'main' java.lang.NoSuchMethodError: main ". Theres no

public static void main(String[] args)

in the code, and i think thats what the error message im getting is referring to. 3-4 of these method simple programs im looking at all dont have that line of code in them, and it says to type it and run it for practice.

Code :

import java.util.Scanner;

public class DateSecondTry
{
private String month;
private int day;
private int year;

public void writeOutput()
{
System.out.println(month + " " + day + ", " + year);
}

public void readInput()
{
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter month, day, and year. ");
System.out.println("DO not use a comma. ");
month = keyboard.next();
day = keyboard.nextInt();
year = keyboard.nextInt();

}

public int getDay()
{
return day;
}
public int getYear()
{
return year;
}


public int getMonth()
{
if (month.equalsIgnoreCase("January"))
return 1;
else if (month.equalsIgnoreCase("Febuary"))
return 2;
else if (month.equalsIgnoreCase("March"))
return 3;
else if (month.equalsIgnoreCase("March"))
return 4;
else if (month.equalsIgnoreCase("May"))
return 5;
else if (month.equals("June"))
return 6;
else if (month.equalsIgnoreCase("July"))
return 7;
else if (month.equalsIgnoreCase("August"))
return 8;
else if (month.equalsIgnoreCase("September"))
return 9;
else if (month.equalsIgnoreCase("October"))
return 10;
else if (month.equalsIgnoreCase("November"))
return 11;
else if (month.equalsIgnoreCase("December"))
return 12;

else
{
System.out.println("Fatal Error");
System.exit(0);
return 0;
}
}
}


thanks for the help

-david
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 28 2005
Added on Oct 30 2005
2 comments
199 views