public static void main(String args[])
Generally we do the following mistakes in this regard:
1. May be, you haven't defined the main method at all. Define it at first then run it.
2. The method name is not correctly written. The spelling will be exactly in lower case 'main', if we write 'Main' - it will be an error.
For example:
public class NoSuchMethodErrorMain
{
public static void Main(String args) // M is capital here
{
System.out.println("Java is an Object Oriented Language");
}
}
3. The keyword 'static' is omitted. The main method must be static.
For example,
public class NoSuchMethodErrorMain
{
public void main(String args) // keyword static is missing
{
System.out.println("Java is an Object Oriented Language");
}
}
4. The parameter is not declared. Java main method must have a String array parameter. Sometimes, we forget to put [] after the data type or the parameter name (args, here).
For example:
public class NoSuchMethodErrorMain
{
public static void main() // parameter problem
{
System.out.println("Java is an Object Oriented Language");
}
}
OR
public class NoSuchMethodErrorMain
{
public static void main(String args) // the parameter is not array
{
System.out.println("Java is an Object Oriented Language");
}
}
The correct code will be:
public class NoSuchMethodErrorMainSolution
{
public static void main(String args[])
{
System.out.println("Java is an Object Oriented Language");
}
}
0 comments:
Post a Comment