Javatpoint Logo

dereferencing null pointer error

By: kabind*** On: Sat Feb 18 20:59:30 IST 2017     Question Reputation0 Answer Reputation0 Quiz Belt Series Points0  0Blank User
I am trying to write program which takes name as input from command line and sort by last name, displayed in format last name, first name. Here is my code which gives dereferencing null pointer error.

public static void main(String[] args)
if(args[0].equals("slst"))
{
System.out.println("Here is a list of the names as read in:");
for(String s: args_name)
{
System.out.println(s);
}
System.out.println("Press Enter to continue ... ");
keyboard.nextLine();
System.out.println("And here is a list of the name sorted by last"
+ " name, displayed in the format Last, First");
String firstName = name.substring(1,name.indexOf(" "));
String lastName = name.substring(name.indexOf(" ") +1);
String slst = lastName + ", " + firstName;
System.out.println(slst);
Up0Down
core java  x  328Tags