我不明白为什么我会不断收到这个空指针异常,我对引用和指针等等一无所知,因此才开始学习类和对象。非常感谢帮助!这是有问题的代码:
public class Library {
public static MediaItem[] item = new MediaItem[100];
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int choice = 0;
int numberOfItems = 0;
System.out.println("Personal Lending Library!");
while (choice !=6) {
choice = menu(input);
switch(choice) {
case 1: addNewItem(numberOfItems, input);
break;
case 2:
break;
case 3: listItems(numberOfItems);
break;
case 4:
break;
}
}
}
public static void addNewItem(int numberOfItems, Scanner input) {
numberOfItems++;
System.out.print("Enter the title: ");
item[numberOfItems].title = input.nextLine();
System.out.print("Enter the format: ");
item[numberOfItems].format = input.nextLine();