Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Can't compile classes due to exception problems

  1. #1
    Junior Member
    Join Date
    May 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Can't compile classes due to exception problems

    These are the error messages that shows up when I try to compile it:
    Main.java:16: error: unreported exception FileNotFoundException; must be caught or declared to be thrown
    FileReader fr = new FileReader ("a.txt"); /*thrown FileNotFoundException;*/
    ^
    Main.java:18: error: unreported exception IOException; must be caught or declared to be thrown
    fr.close();
    ^
    Here is my code
    import java.util.Scanner;
    import java.util.List;
    import java.io.BufferedReader;
    import java.io.FileReader;
     
     
    public class Main {
      public static void main (String [] args) {
        String configurationFile = "a.txt";
        FileReader fr = new FileReader ("a.txt"); /*thrown FileNotFoundException;*/
        BufferedReader br = new BufferedReader (fr);
        fr.close();
      }
    }

    Thanks for any input


  2. #2
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Posts
    834
    My Mood
    Cynical
    Thanks
    7
    Thanked 105 Times in 90 Posts

    Default Re: Can't compile classes due to exception problems

    Have a look at the following page which discuss the use of exceptions

    Lesson: Exceptions (The Java™ Tutorials > Essential Classes)

    How to throw and catch them for example. You need to be catching these exceptions as they are checked exceptions, this means you cannot compile without handling these in one way or another.

    Chris

Similar Threads

  1. Problems with Inner Classes
    By tyeeeee1 in forum Java Theory & Questions
    Replies: 3
    Last Post: December 12th, 2012, 07:46 PM
  2. Two problems (Dealing with Classes and Objects)
    By AustinStanley in forum What's Wrong With My Code?
    Replies: 5
    Last Post: December 4th, 2012, 08:17 PM
  3. Can't compile .java file in JDeveloper due to missing files
    By javanewbie2 in forum Java Theory & Questions
    Replies: 4
    Last Post: July 7th, 2011, 10:22 AM
  4. [SOLVED] Error: Null Exception on Array of classes
    By g000we in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 15th, 2010, 09:14 AM
  5. Exception and Serialization Problems
    By chrisych in forum Exceptions
    Replies: 0
    Last Post: February 7th, 2010, 11:30 AM