so i have a private String[] teamName;. all i want to do is simply use a String output by a user and store that String into String[] teamName;. I am taking teamName[team] and equaling it to = keyboard.nextLine(), doing this is giving me a nullexpection error. why?
so for this is what i have ...
private String[] teamName; // contains an entry for each team
public void enterInData( )
{
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter number of teams:");
numberOfTeams = keyboard.nextInt( );
System.out.println("Enter number of weeks:");
numberOfWeeks = keyboard.nextInt( );
scores =new int [numberOfTeams][numberOfWeeks];
// ************** Fill in Code ***************
// Allocate array memory for teamName to store the team names.
// Allocate array memory for scores (2 dimensional array) to store a
// score for each team for each week.
teamName = new String[4];
for (int team = 0; team < numberOfTeams; team++)
{
System.out.println("Enter team name");
// ************* Fill in Code **************
// Read in Team name and store it in teamName
teamName = new String[team];
teamName[team] = keyboard.nextLine();
for (int week = 0; week < numberOfWeeks; week++)
{
System.out.println("Enter score for team "+ teamName[team]);
System.out.println("on week number " + (week+1));
// ************ Fill in Code ***************
// Read in a score and store it in the proper spot in the scores array
scores[team][week] = keyboard.nextInt();
}
}