/** *Method called by the menu to gather, transform, and verify user *input to be used in the findFile() recursive method *If the input is valid, the findFile() method is called with the parameter *If the input is invalid, action is taken to ensure valid input */ public static void callFindFilePath() { //lets user know the method has been called and creates Scanner for input System.out.println("callFindFilePath() has been called" + "\n"); Scanner input = new Scanner(System.in);    //declares flag variable for when user does not want to try again boolean tryAgain = true; String findFile = ""; String startDirectory = "";    //while loop that continues until user exits the method while(tryAgain) { try { //prompts user to enter a directory to search for a file in //and sets input to variable answer, also creates File object set to user input System.out.print("Please Enter a Start Path> "); startDirectory = input.nextLine(); File directory = new File(startDirectory);    //checks to see if user input is a valid directory or no if(directory.isDirectory()) { //prompts user to enter a file to find paths for System.out.print("Please Enter a File to Find the Paths of> "); findFile = input.nextLine(); File searchFile = new File(findFile);    // System.out.println("findFile() has been called"); findFile(searchFile, directory); System.out.println(""); tryAgain = mainMenu(); }    //throws argument if user input is not a valid directory else throw new IllegalArgumentException(); }    //catches user input not being a valid directory and prompts user to return to main menu or not catch(IllegalArgumentException iae) { System.out.println(startDirectory + " Is Not a Valid Starting Directory, Please Try Again" + "\n"); tryAgain = mainMenu(); } } }    /** *The basic findFile algorithm *This method does not check the parameters and it's only called by *the callFindFilePath() method * *@param targetFileName the file to have its absolute path searched for and printed *@param startPath the starting directory to be searched for targetFileName */ public static void findFile(File targetFileName, File startPath) { //creates File array and populates it with all files in startPath File [] fileArray = startPath.listFiles();    //iterates through fileArray to find matching file to targetfileName for(int i = 0; i < fileArray.length; i++) { // if(fileArray[i].isFile()) if(fileArray[i].getName().matches(targetFileName.getName())) System.out.println(fileArray[i].getAbsolutePath() + "\n");    // else findFile(targetFileName,fileArray[i]); } }   I keep getting this error: -----------Options Menu----------- A) Summation B) Isabel's Technique C) Find File Path Q) Quit Enter Choice> c callFindFilePath() has been called Please Enter a Start Path> rdty rdty Is Not a Valid Starting Directory, Please Try Again Would You Like to Return to the Main Menu (Y/N)> C;\\ Please Enter Either Y or N Would You Like to Return to the Main Menu (Y/N)> n Please Enter a Start Path> C:\\Windows Please Enter a File to Find the Paths of> BCD findFile() has been called Exception in thread "main" java.lang.NullPointerException: Cannot read the array length because "fileArray" is null    at Recursion.findFile(Recursion.java:303)    at Recursion.findFile(Recursion.java:312)    at Recursion.callFindFilePath(Recursion.java:270)    at Client.main(Client.java:56) C:\Users\Noahh\AppData\Local\NetBeans\Cache\14\executor-snippets\run.xml:111: The following error occurred while executing this line: C:\Users\Noahh\AppData\Local\NetBeans\Cache\14\executor-snippets\run.xml:68: Java returned: 1 BUILD FAILED (total time: 19 seconds) Please Help

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

/**
*Method called by the menu to gather, transform, and verify user
*input to be used in the findFile() recursive method
*If the input is valid, the findFile() method is called with the parameter
*If the input is invalid, action is taken to ensure valid input
*/
public static void callFindFilePath()
{
//lets user know the method has been called and creates Scanner for input
System.out.println("callFindFilePath() has been called" + "\n");
Scanner input = new Scanner(System.in);
  
//declares flag variable for when user does not want to try again
boolean tryAgain = true;
String findFile = "";
String startDirectory = "";
  
//while loop that continues until user exits the method
while(tryAgain)
{
try
{
//prompts user to enter a directory to search for a file in
//and sets input to variable answer, also creates File object set to user input
System.out.print("Please Enter a Start Path> ");
startDirectory = input.nextLine();
File directory = new File(startDirectory);
  
//checks to see if user input is a valid directory or no
if(directory.isDirectory())
{
//prompts user to enter a file to find paths for
System.out.print("Please Enter a File to Find the Paths of> ");
findFile = input.nextLine();
File searchFile = new File(findFile);
  
//
System.out.println("findFile() has been called");
findFile(searchFile, directory);
System.out.println("");
tryAgain = mainMenu();
}
  
//throws argument if user input is not a valid directory
else
throw new IllegalArgumentException();
}
  
//catches user input not being a valid directory and prompts user to return to main menu or not
catch(IllegalArgumentException iae)
{
System.out.println(startDirectory + " Is Not a Valid Starting Directory, Please Try Again" + "\n");
tryAgain = mainMenu();
}
}
}
  
/**
*The basic findFile algorithm
*This method does not check the parameters and it's only called by
*the callFindFilePath() method
*
*@param targetFileName the file to have its absolute path searched for and printed
*@param startPath the starting directory to be searched for targetFileName
*/
public static void findFile(File targetFileName, File startPath)
{
//creates File array and populates it with all files in startPath
File [] fileArray = startPath.listFiles();
  
//iterates through fileArray to find matching file to targetfileName
for(int i = 0; i < fileArray.length; i++)
{
//
if(fileArray[i].isFile())
if(fileArray[i].getName().matches(targetFileName.getName()))
System.out.println(fileArray[i].getAbsolutePath() + "\n");
  
//
else
findFile(targetFileName,fileArray[i]);
}
}

 

I keep getting this error:

-----------Options Menu-----------
A) Summation
B) Isabel's Technique
C) Find File Path
Q) Quit

Enter Choice> c
callFindFilePath() has been called

Please Enter a Start Path> rdty
rdty Is Not a Valid Starting Directory, Please Try Again

Would You Like to Return to the Main Menu (Y/N)> C;\\
Please Enter Either Y or N

Would You Like to Return to the Main Menu (Y/N)> n

Please Enter a Start Path> C:\\Windows
Please Enter a File to Find the Paths of> BCD
findFile() has been called
Exception in thread "main" java.lang.NullPointerException: Cannot read the array length because "fileArray" is null
   at Recursion.findFile(Recursion.java:303)
   at Recursion.findFile(Recursion.java:312)
   at Recursion.callFindFilePath(Recursion.java:270)
   at Client.main(Client.java:56)
C:\Users\Noahh\AppData\Local\NetBeans\Cache\14\executor-snippets\run.xml:111: The following error occurred while executing this line:
C:\Users\Noahh\AppData\Local\NetBeans\Cache\14\executor-snippets\run.xml:68: Java returned: 1
BUILD FAILED (total time: 19 seconds)


Please Help  

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Computational Systems
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY