Click here to Skip to main content
15,907,874 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have written a code using External Methods.

The code compiles successfully.
Once I run the Application it prompts me the following:
"Exception in thread "main" java.lang.NoSuchMethodError: main"

I can't see what I'm doing wrong.

What I have tried:

import java.io.*;

public class Employee
{
	String FirstName;
	String LastName;
	String Position;
	float Rate;
	float Hours;

	public Employee(String f, String l, String p, float r, float h)
    {
        FirstName = f;
        LastName = l;
        Position = p;
        Rate = r;
        Hours = h;
    }
    public Employee(String f,String l, String p)
    {
		LastName = l;
        FirstName = f;
        Position = p;
    }
    public String getFirstName()
    {
        return FirstName;
    }
    public String getLastName()
    {
        return LastName;
    }
    public String getPosition()
    {
        return Position;
    }
    public float getRate()
    {
        return Rate;
    }
    public float getHours()
    {
        return Hours;
    }
}
Posted
Updated 28-Aug-18 5:32am

1 solution

I am not sure what you mean by "I have written a code using External Methods."

However, you get that message because there is no main method in your class, so it cannot run on its own. You need to add a main method (see below), and also the remaining code to drive this class and actually do something.
Java
// add this inside the Employee class
    public static void main(String[] args) {
        // Add code here to create objects and interface with the user.
    }
 
Share this answer
 
Comments
Member 13652359 29-Aug-18 9:25am    
Once I do that I get the following errors:

C:\Java 1\New folder (3)\Chapter05\Employee.java:16: ')' expected
Employee(String f, String l, String p, float r, float h)
^
C:\Java 1\New folder (3)\Chapter05\Employee.java:50: ';' expected
}
^
2 errors

Tool completed with exit code 1
Richard MacCutchan 29-Aug-18 11:43am    
That looks like you have added the main method inside the constructor. I suggest you go and work through Trail: Learning the Java Language (The Java™ Tutorials)[^] to see how to do it correctly.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900