Click here to Skip to main content
15,906,624 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - unreported exception java.io.FileNotFoundException; must be caught or declared to be thrown


What I have tried:

 public static void main(String[] args) {
        double [] Array1 = new double [100];
        try{
            File f1 = new File ("weights.txt");
            Scanner in = new Scanner(f1);
           // Scanner in = new Scanner(new File ("weights.txt"));
            int count = 0;
            while (in.hasNext())
            {
            String [] stone = in.nextLine().split("");
            for (String temp:stone)
            {
             double KG = (Double.valueOf(temp))* 6.35029318 ;
              Array1 [count] = KG;
              count++ ;
            }
            }
            double [] Array2 = new double [count];
            copyArray (Array1 , Array2 , count);
            in.close();
            in = new Scanner (System.in);
            
            String choice = " " ;
            DecimalFormat df = new DecimalFormat("0.00");
            while (!choice.equalsIgnoreCase("Q")) {
                System.out.println("menu\np.print the file\r\n"
                        + "D.display sorted list\r\n"
                        + "S.search \r\n"
                        + "Q. Quit ");
                System.out.print("Enter your choice");
                choice = in.nextLine();
            
                switch(choice.toUpperCase().charAt(0))
                {
                    case 'p' :
                        for(int i=0; i<count;i++){
                            System.out.printf("%.2f",Array2[i]);
                }
                
                
                break ;
                   case 'D' :
                   Arrays.sort(Array2);
                   for (int i =0 ; i<count ; i++){
                   System.Out.printf("%.2f", Array2[i]);
            }
            break;
                   case 'S' :
                   System.Out.println("Enter a number ");
                   double number = in.nextDouble();
                   in.nxetLine();
                   boolean tempfound = false ;
                   for (int i=0 ; i <count ; i++){
                   String num = df.format(Array2[i]);
                   if(String.valueOf(number).equalsignoreCase(num)){
                   System.Out.printLn("The given value is found");
                   tempfound = true ;
            }
                   }
            
                
              if(!tempfound)
              System.out.printIn("The given value is not found ");
                 break;
                 case 'Q' :
                 System.out.printIn("End");
                 break;
                 default :
                 System.out.printIn("invalid choice");
            }
              System.out.print("\n");
         
        
        }catch (FileNotFoundException e) {
            System.out.println("xxx");
        }
    
}

    
   private static void copyArray (double[] Array1 ,double [] Array2 , int count ) {
            for (int i=0 ; i<count ; i++){
                Array2[i] = Array1[i];
            }
          }
}
Posted
Updated 8-Jan-22 4:59am
Comments
0x01AA 8-Jan-22 10:53am    
It seems you haven't even corrected the bug you asked for help in your last question ...

1 solution

Read the error message: a file cannot be found.
At a guess:
File f1 = new File ("weights.txt");
And weights.txt does not exist in the exe folder.

Use the debugger to follow your code through and check, then check where the file is and correct your path.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900