Java FileNotFoundException error as statement not in a method
<p>I have 2 files where 1(OrderCatalogue.java) reads in contents of a external file and 2(below). But I'm having the "FileNotFoundException must be caught or declard to be thrown" error for this line "OrderCatalogue catalogue= new OrderCatalogue();" and I understand that because its not in a method. But if i try puting it in a method, the code under the "getCodeIndex" and "checkOut" methods can't work with the error message of "package catalogue does not exist". Anyone has any idea how i can edit my code to make them work? Thank you!!</p>

<pre><code>public class Shopping {

OrderCatalogue catalogue= new OrderCatalogue();
ArrayList&lt;Integer&gt; orderqty = new ArrayList&lt;&gt;(); //Create array to store user's input of quantity
ArrayList&lt;String&gt; ordercode = new ArrayList&lt;&gt;(); //Create array to store user's input of order number

    public int getCodeIndex(String code)
    {    
        int index = -1;

        for (int i =0;i&lt;catalogue.productList.size();i++)
        {            
            if(catalogue.productList.get(i).code.equals(code))
            {
            index = i;
            break;
            }
        }
        return index;
    }
    public void checkout()
    {
         DecimalFormat df = new DecimalFormat("0.00");
         System.out.println("Your order:");
         for(int j=0;j&lt;ordercode.size();j++)
         {
            String orderc = ordercode.get(j);

            for (int i =0;i&lt;catalogue.productList.size();i++)
            {
                if(catalogue.productList.get(i).code.equals(orderc))
                {
                    System.out.print(orderqty.get(j)+" ");
                    System.out.print(catalogue.productList.get(i).desc);
                    System.out.print(" @ $"+df.format(catalogue.productList.get(i).price)); 
                }
            }   
        }

    }
</code></pre>

<p>And this is my OrderCatalogue file</p>

<pre><code>public OrderCatalogue() throws FileNotFoundException

{

    //Open the file "Catalog.txt"
           FileReader fr = new FileReader("Catalog.txt");
           Scanner file = new Scanner(fr);


           while(file.hasNextLine())
           {
               //Read in the product details in the file
               String data = file.nextLine();
               String[] result = data.split("\\, "); 

               String code = result[0];
               String desc = result[1];
               String price = result[2];
               String unit = result[3];

               //Store the product details in a vector
               Product a = new Product(desc, code, price, unit);

               productList.add(a);
           }
</code></pre>
