I am having a problem with a java program. Exception in thread "main"
1)Batman
Exception in thread "main" java.land.NullPointerException
at Superhero.printInfo(superhero.java:46)
at Superhero.main(Superhero.java:85)
is the error. This is the full code:
import java.util.Scanner;
public class Superhero{
String [] firstName = new String [5];
String [] lastName = {"Wayne","Kent","Diana","Authur","Quinzel"};
String [] email = {"batman@gmail.com", "superman@gmail.com", "wonder@gmail.com", "aquaman@gmail.com", "quinn@gmail.com"};
public Superhero() {
firstName[0] = "Bruce";
firstName[1] = "Clark";
firstName[2] = "Wayne";
firstName[3] = "Curry";
firstName[4] = "Harleen";
}
// Assing values of supeheros.
// @param entry - an superhero instance to be filled
/**
**/
public static Superhero SuperheroInfo(Superhero entry, Scanner inputs){
// input first name
System.out.print("Enter First Name: ");
String input1 = inputs.next();
// input last name
System.out.print("Enter Last Name: ");
String input2 = inputs.next();
// input email
System.out.print("Enter Email: ");
String input3 = inputs.next();
return entry;
}
// Print all information.
public static void printInfo(Superhero entry) {
System.out.println("First Name: " + entry.firstName);
System.out.println("Last Name: " + entry.lastName);
System.out.println("Email: " + entry.email);
}
// Main method
public static void main(String[] args) {
Superhero superhero1 = null;
Superhero superhero2 = null;
Superhero superhero3 = null;
Superhero superhero4 = null;
Superhero superhero5 = null;
Scanner scanner = new Scanner(System.in);
// Data entries for all superheros
System.out.println("Superhero 1 Data Entry");
superhero1 = SuperheroInfo(superhero1, scanner);
System.out.println("\nSuperhero 2 Data Entry");
superhero2 = SuperheroInfo(superhero2, scanner);
System.out.println("\nSuperhero 3 Data Entry");
superhero3 = SuperheroInfo(superhero3, scanner);
System.out.println("\nSuperhero 4 Data Entry");
superhero4 = SuperheroInfo(superhero4, scanner);
System.out.println("\nSuperhero 5 Data Entry");
superhero5 = SuperheroInfo(superhero5, scanner);
// Print out all superhero information
System.out.println("***********************");
System.out.println("Classified Information");
System.out.println("***********************");
System.out.println("\n1) Batman");
printInfo(superhero1);
System.out.println("-------------------------");
System.out.println("\n2) Superman");
printInfo(superhero2);
System.out.println("-------------------------");
System.out.println("\n3) Wonderwoman");
printInfo(superhero3);
System.out.println("-------------------------");
System.out.println("\n4) Aquaman");
printInfo(superhero4);
System.out.println("-------------------------");
System.out.println("\n5) Harley Quinn");
printInfo(superhero5);
System.out.println("-------------------------");
return;
}
}
Im just starting out on programming so its a bit confusing at times. Could really use some help, as I've been stuck on this for hours.
Im just adding words now coz the system wont let me post. Im just adding words now coz the system wont let me post. Im just adding words now coz the system wont let me post. Im just adding words now coz the system wont let me post. Im just adding words now coz the system wont let me post. Im just adding words now coz the system wont let me post. Im just adding words now coz the system wont let me post. Im just adding words now coz the system wont let me post. Im just adding words now coz the system wont let me post.