I get the above error when I try to compile this simple program:
/* @author
* This program expects two command-line arguments
* -- a person's first name and last name.
* For example:
* C:\Mywork> java Greetin Annabel Lee
*/
public class Greetin
{
public static void main(String[] args)
{
String firstName = args[0];
String lastName = args[1];
System.out.println("Hello, " + firstName + " " + lastName);
System.out.println("Congratulations on your second program!");
}
}
From looking at other questions, I understand the error has something to do with args == 0 and 0 being greater than the number, but I don’t know how to fix the problem for this case.
Is there any way the error is also identified as being caused by the void?
My guess is there aren’t any args supplied to your program. Good convention is to make sure the user inputs the expected amount of args, else die. In your case:
Also, make sure you type:
java Greetin Annabel Leeafter you compile to properly set the arguments.