Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

Help with null pointer exception! 'm trying to finish a program in which i add values to an array list from user input and organize

Help with null pointer exception! 'm trying to finish a program in which i add values to an array list from user input and organize them via comparable, but i keep getting a null pointer exception. Can someone help me?

package fiucs;

/** * * @author **************** */ import java.util.ArrayList; import java.util.Collections; import java.util.Scanner; public class FIU { static ArrayList Courses; public static void main(String[] args){ FIU myFIU = new FIU(); Scanner keyboard = new Scanner(System.in); int j = 1; //Variable for menu 1 = continue, 2 = stop createArrayList(keyboard); do { UserMenu(); System.out.println("Do you wish to proceed? (1 for yes, 2 for no)"); j = keyboard.nextInt(); }while(j==1); keyboard.close();; } public static ArrayList createArrayList(Scanner keyboard){ ArrayList Courses; Courses = new ArrayList(); String FIUCourseName; String FloridaCourseName; int yearLevel; double credits; ArrayList preReqs = new ArrayList(); int i = 1; //Prompt the user to enter the courses required for the IT major do{ System.out.println("What is the name of the course you wish to take?"); FIUCourseName = keyboard.next(); System.out.println("What is the Florida course name for the selected class?"); FloridaCourseName = keyboard.next(); System.out.println("What is your academic year level?"); yearLevel = keyboard.nextInt(); System.out.println("How many credits is the course worth?"); credits = keyboard.nextDouble(); System.out.println("Do you want to eneter another course? (Press 1 for Yes, 2 for no)"); i = keyboard.nextInt(); Courses.add(new Course(FIUCourseName, credits, FloridaCourseName, yearLevel, preReqs)); }while (i==1); return Courses; } public static void UserMenu(){ System.out.println(" By Fiu Course Name"); Collections.sort(Courses); for(int i = 0; i System.out.println(Courses.get(i)); } System.out.println(" By Year Level"); Collections.sort(Courses, new YearComparator()); for(int i = 0; i System.out.println(Courses.get(i)); } System.out.println(" By Florida Course Name"); Collections.sort(Courses, new FLNameComparator()); for(int i = 0; i System.out.println(Courses.get(i)); } } }

I keep getting this error. Help?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

App Inventor

Authors: David Wolber, Hal Abelson

1st Edition

1449397484, 9781449397487

More Books

Students explore these related Programming questions