0

My code breaks when the user is supposed to input a unique number for itemNumber, however there is no error displayed in NetBeans, can someone help me with why this happens?

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]);
        }
    }
}
Cody Gray
  • 222,280
  • 47
  • 466
  • 543
Warigle
  • 3
  • 2
  • 1
    Which line is 38? – Joe C Feb 17 '19 at 10:16
  • 1
    Why do you have so many Scanners reading from `System.in`? This stream should be handled by *one* Scanner on which you will call all `next...()` methods. Even if you are facing problem described at [Scanner is skipping nextLine() after using next() or nextFoo()?](https://stackoverflow.com/q/13102045) use solutions from that question, having many Scanners will cause you more problems in more complex application. – Pshemo Feb 17 '19 at 11:22
  • You are not allowed to vandalize your posts. Please read our Terms of Service and the license agreement under which you submitted your question. – Cody Gray Feb 18 '19 at 07:09

1 Answers1

1

Haven't seen your error message, but probably you've got the error because your array reference is null

int[] itemNumber;
itemNumber = null

In order to fix this, replace these lines with this one:

int[] itemNumber = new int[numberOfItems];
Andrey Antipov
  • 350
  • 3
  • 9