为什么我不能在第 38 行输入多个 itemNumber

Why can I not input a number of itemNumber at line 38

当用户应该为 itemNumber 输入一个唯一的数字时,我的代码中断了,但是 NetBeans 中没有显示错误,有人可以帮我解释为什么会这样吗?

package pre_release;
import java.util.*; 

public class Pre_Release {

    public static void main(String[] args) {
        int numberOfItems = 0;
        int number;
        int bidNumber;
        double highestBid = 0;
        Scanner userInput = new Scanner (System.in);
        Scanner userString = new Scanner (System.in); 
        Scanner userDouble = new Scanner (System.in); 
        Scanner userBuyer = new Scanner (System.in); 
        Scanner userInt = new Scanner (System.in);
        Scanner userItem = new Scanner (System.in);
        do{
            System.out.println("Please enter the the amount of items for the auction. Needs to be more than or equal to 10"); 
            numberOfItems = userInput.nextInt();
        } while(numberOfItems<10);
        String[] description = new String[numberOfItems];  
        double[] reservePrice = new double[numberOfItems];
        double[] bid = new double[numberOfItems]; 
        int[] itemNumber;
        itemNumber = null;
        int[] buyNumber = new int[numberOfItems]; 
        for(int count=0;count<numberOfItems;count++){
            System.out.println("Input a number for each item number");
            itemNumber[count] = userInt.nextInt();
        }
        for(int count=0;count<numberOfItems;count++){
            bidNumber=0;
            System.out.println("Please give your item a reserved price");
            reservePrice[count] = userDouble.nextDouble(); 
            System.out.println("Please describe your item");
            description[count] = userString.nextLine();
        }
        System.out.println("Please enter the desired item you wish to see");
        number = userInt.nextInt(); 
        for(int count2=0;count2<numberOfItems;count2++){
            if(itemNumber[count2] == number){
                System.out.println("The reserved price is" + reservePrice[numberOfItems]);
                System.out.println(description[numberOfItems]);
            }
            System.out.println("Would you like to put a bid on this item? Needs to be more than" + reservePrice[numberOfItems]);
        }
    }
}

没有看到您的错误消息,但可能是因为您的数组引用为 null

int[] itemNumber;
itemNumber = null

为了解决这个问题,将这些行替换为这一行:

int[] itemNumber = new int[numberOfItems];