Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8098989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:15:27+00:00 2026-06-05T22:15:27+00:00

The following program I’m creating will allow the user will input values to create

  • 0

The following program I’m creating will allow the user will input values to create an array of videos. Each video contains several data fields (number, title, publisher, duration & date). The program is primarily controlled through a switch menu. However after creating the array, choosing another option, such as Show videos will throw a Null Pointer Exception. These exceptions usually occur when you haven’t assigned values to the array, but that should have been already done in the first option, createLibrary(). Other functions in Search videos and Change videos have the same issue and it occurs every time a get method is used.

Anyone with a reasonable practical answer will greatly help.

Here is a segment of my code:

import java.util.*;
public class EnterLibrary
{
public final int MAX_ITEMS = 5;
public Library[] videos;
public int size = 0;

public EnterLibrary()
    {
        videos = new Library[MAX_ITEMS];
        java.util.Scanner scannerObject =new java.util.Scanner(System.in);
        LibraryMenu Menu = new LibraryMenu();
        Menu.displayMenu();
        switch (scannerObject.nextInt())
        {
            case 1:
            System.out.println ("1 - Add Videos");
                if (size < MAX_ITEMS) {
                Library video = createLibrary();
                videos[size++] = video;
                }
            new EnterLibrary();
            break;
            case 2:
            System.out.println ("2 - Show Videos");
            printVidLibrary(videos);
            new EnterLibrary();
            break;
            case 3:
            System.out.println ("3 - Search Videos");
            searchLibrary(videos);
            new EnterLibrary();
            break;
            case 4:
            System.out.println ("4 - Change Videos");
            changeLibrary(videos);
            break;      
            case 5:
            System.out.println ("5 - Delete Videos");
            deleteVideo(videos);
            new EnterLibrary();
            break;
            default:
            System.out.println ("Unrecognized option - please select options 1-5 ");
            break;
        }
    }

public Library createLibrary()
{
    Library video = new Library();
    java.util.Scanner scannerObject =new java.util.Scanner(System.in); 
    for (int i = 0; i < videos.length; i++)
    {
    //User enters values into set methods within the Library class
    System.out.print("Enter video number: " + (i+1) + "\n");
    String number = scannerObject.nextLine();
    System.out.print("Enter video title: " + (i+1) + "\n");
    String title = scannerObject.nextLine();
    System.out.print("Enter video publisher: " + (i+1) + "\n");
    String publisher = scannerObject.nextLine();
    System.out.print("Enter video duration: " + (i+1) + "\n");
    String duration = scannerObject.nextLine();
    System.out.print("Enter video date: " + (i+1) + "\n");
    String date= scannerObject.nextLine();
    System.out.print("VIDEO " + (i+1) + " ENTRY ADDED " + "\n \n");
    //Initialize arrays
    videos[i] = new Library ();
    videos[i].setVideo( number, title, publisher, duration, date  );
    }
    return video;
}

public void printVidLibrary( Library[] videos)
{
    //Get methods to print results
    System.out.print("\n***VIDEO CATALOGUE*** \n");
    for (int i = 0; i < videos.length; i++)
    {
    System.out.print("Video number " + (i+1) + ": \n" + videos[i].getNumber() + "\n ");
    System.out.print("Video title " + (i+1) + ": \n" + videos[i].getTitle() + "\n ");
    System.out.print("Video publisher " + (i+1) + ": \n" + videos[i].getPublisher() + "\n ");
    System.out.print("Video duration " + (i+1) + ": \n" + videos[i].getDuration() + "\n ");
    System.out.print("Video date " + (i+1) + ": \n" + videos[i].getDate() + "\n ");
    }
}
//Code for other functions not displayed here

public static void main(String[] args)
    {

    new EnterLibrary();
    }
}

The exception error:

Exception in thread "main" java.lang.NullPointerException
        at EnterLibrary.printVidLibrary(EnterLibrary.java:80)
        at EnterLibrary.<init>(EnterLibrary.java:26)
        at EnterLibrary.<init>(EnterLibrary.java:22)
        at EnterLibrary.<init>(EnterLibrary.java:22)
        at EnterLibrary.<init>(EnterLibrary.java:22)
        at EnterLibrary.<init>(EnterLibrary.java:22)
        at EnterLibrary.main(EnterLibrary.java:202)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T22:15:30+00:00Added an answer on June 5, 2026 at 10:15 pm

    There are at least two serious errors in your code:

    1. There’s a stack overflow waiting to happen: you’re calling EnterLibrary() inside EnterLibrary(), that will produce an infinite recursion
    2. Although you have instantiated the videos array, you haven’t initialized it yet ant it’s full of null objects; make sure to call createLibrary() at the beginning of EnterLibrary‘s constructor, before calling printVidLibrary(), which iterates over all the contents of videos and assumes that it’s entirely initialized
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following program expects user input in the mixed fraction format 'whole_numbernumerator/denominator' and assigns
When I execute the following program it get the user input for account details
The following program will not compile: class Program { static void Main(string[] args) {
The following program reads a file and it intends to store the all values
The following program will fail because Contracts is not instantiated. Of course I can
The following program static IEnumerable<Action> Create() { foreach (var i in Enumerable.Range(0, 2)) {
The following program (taken from a tutorial) prints the numbers in an array in
The following program is very simple: it outputs a single dot each half a
The following program when run will product stackoverflow as output. I want to know
I have created the following program which allows a user to guess a word

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.