0
 public static void searchCustomer(){
        Scanner input=new Scanner(System.in);
      L1:do{
            clearConsole();
            searchCustomerHomepage();
            
            
            System.out.print("Enter Customer phone number : ");
            String phone=input.next();
            if(!isValidTpnumber(phone)){
                System.out.println("\n\tInvalid input :");
                
            }
            int i=searchingArray(phone);
            if(i!=-1){
                System.out.println(orderIdArray[i]);
                System.out.println(customerContactArray[i]);
                System.out.println(tshirtSizeArray[i]);
                System.out.println(amountArray[i]);
                
                }
            System.out.print("Do you want to search another customer report? (Y/N)");
            char op=input.next().charAt(0);
            if(op=='Y'||op=='y'){
                continue L1;
            }
        }while(true);
    }







    //////SEARCHINGARRAY/////
    public static int searchingArray(String phone){
        for(int i=0;i<customerContactArray.length;i++){
            if(customerContactArray[i].equals(phone)){
                return i;
            }
        }
        return -1;
    }




In this code why null exception error occuring.I will put the error below.. Exception in thread "main" java.lang.NullPointerException at fashion.searchingArray(fashion.java:15) at fashion.searchCustomer(fashion.java:257) at fashion.main(fashion.java:127)

I want to solve above error & want to get knowledge about that mistake..I hope code is clear for you

Yasith
  • 1
  • Depending on what line `257` exactly is, either `customerContactArray` itself or one of its entries is `null` ... – derpirscher Aug 23 '23 at 09:03
  • BTW: Your loop will never exit, because if you enter anything different from `Y` or `y` it will still continue, because of the `while (true)` – derpirscher Aug 23 '23 at 09:05
  • The actual error happens in line 15. If that line is the one that starts the `for` loop, then your array is `null`. If it's the next line, with the `if` statement, then the element `i` of your array is `null`. – k314159 Aug 23 '23 at 09:13
  • @k314159 Yes, you are right, took the wrong line number from the error message, but still meant the code inside the `searchingArray` method ... – derpirscher Aug 23 '23 at 11:36

0 Answers0