0

コレクションにある本と、各本が何部あるかを記録する図書館プログラムを作成しています。ここにコードがあります

import java.util.Arrays;
import java.util.Scanner;
public class Library{
  static String title;
  static String author;
  static int id;
  static int copies;
  static String date;
  static Book[] database = new Book[100];
  static int count=0;

  public static void main(String[] args){
    int i;
    Scanner s = new Scanner(System.in);
    do{
      addBook();
      System.out.println("would you like to add another book?");
      i=s.nextInt();
    }while(i == 0);
    database[0].viewDetails();
    database[1].viewDetails();
    checkingOut();
  }
  public static void addBook(){
    Scanner s = new Scanner(System.in);
    System.out.println("Enter the title of the book you want to add to the collection");
    title=s.nextLine();
    System.out.println("Enter the author of the book you want to add to the collection");
    author=s.nextLine();
    System.out.println("Enter the publishing date of the book you want to add to the collection");
    date=s.nextLine();
    System.out.println("Enter the ID number of the book you want to add to the collection");
    id=s.nextInt();
    System.out.println("Enter the the number of copies that will be added into the collection");
    copies=s.nextInt();

    Book Book1 = new Book(date, author, copies, id, title);
    database[count] = Book1;
    count++;
  }
  public static void checkingOut(){
    boolean found=false;
    int idSearch;
    int i=0;
    Scanner s = new Scanner(System.in);
    System.out.println("Enter the ID number of the book you want to check out");
    idSearch=s.nextInt();
    while(i<database.length && found!=true){
      if(database[i].getIdentificationNumber() == idSearch){
        found = true;
      }
      i++;
    }
    if(found==true){
      database[i].checkOut();
      System.out.println("There are "+database[i].getNumberCopies()+" copies left");
    }
    else{System.out.println("There is no book with that ID number!");}
  }
}

チェックアウト メソッドの 55 行目でヌル ポインター例外が発生します。理由がわかりません。それが何かを見つけることができれば、私に知らせてください。どんな助けでも大歓迎です。

4

3 に答える 3