Results 1 to 2 of 2
  1. #1
    iochinome is offline Member
    Join Date
    Dec 2010
    Posts
    1
    Rep Power
    0

    Default FileReader errors

    hello all,

    I am new to java and trying to build and run the code below on netbeans IDE, and for some reason I am getting a error message which I cannot solve. could somebody please make a suggestion how to fix this error message? this is exactly how the code appears in multiple tutorials, which is why I am confused. the error message I am getting is:

    run:
    Java Code:
    Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - unreported exception java.io.FileNotFoundException; must be caught or declared to be thrown
    at fileiotest.Main.main(Main.java:25)
    Java Result: 1
    The file that I want to read is definitely in the right place, on my desktop. Here is the code itself:
    Java Code:
    package fileiotest;
    
    import java.io.*;
    import java.util.*;
    import java.io.FileReader;
    
    public class Main {
    
        public static void main(String[] args) {
    
            FileReader fr = new FileReader ("/home/iochinome/Desktop/wdbc.data");
    
        }
    
    }

    and strangely enough, it throws the same error message even when i replace the line
    Java Code:
    FileReader fr = new FileReader ("/home/iochinome/Desktop/wdbc.data");
    with
    Java Code:
    File f = new File("/home/iochinome/Desktop/wdbc.data");
    FileReader fr = new FileReader ("/home/jay/Desktop/wdbc.data");
    Thanks!!!! I really appreciate it!

    - iochi

  2. #2
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    952
    Rep Power
    5

    Default

    The problem is not with the placement of your data file. That would be a runtime error, and what you're seeing is a compile-time error. The error tells you exactly what the problem is, but of course, being new, it's a little intimidating and confusing.

    Java Code:
    Uncompilable source code - unreported exception java.io.FileNotFoundException; must be caught or declared to be thrown
    If you look at the javadoc for FileReader (FileReader (Java Platform SE 6)) you will see that the FileReader constructor can throw a FileNotFound exception. This is a checked Exception, which means that you must either handle it in your code (with a try/except block), or your code must declare it as well (with a throws declaration in the method header).

    Read up on Exceptions in the Java Tutorials.

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

    -Gary-
    Last edited by gcalvin; 12-04-2010 at 07:15 AM.

Similar Threads

  1. problem regarding FileReader
    By mukeshpaliwal in forum New To Java
    Replies: 7
    Last Post: 10-01-2010, 04:15 PM
  2. FileReader problems
    By Maikl in forum New To Java
    Replies: 3
    Last Post: 12-14-2009, 12:51 PM
  3. FileReader help
    By emp in forum New To Java
    Replies: 1
    Last Post: 07-28-2009, 05:41 AM
  4. add FileReader to GUI
    By VinTiger in forum New To Java
    Replies: 8
    Last Post: 05-11-2009, 01:23 AM
  5. Replies: 3
    Last Post: 03-08-2009, 02:51 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •