0

Im getting Exception in thread "main" java.lang.Error: Unresolved compilation: at FileTest.main(FileTest.java:39) Line 39 is public static void main(String[] args){what am I doing wrong?

public class FileTest{
    public static void main(String[] args){

        try{
            String inFileName = args[0];
            String outFileName = args[1];
            BufferedReader ins= new BufferedReader(new FileReader(inFileName));
            BufferedReader con = new BufferedReader(new InputStreamReader(System.in));
            PrintWriter outs = new PrintWriter(new FileWriter(outFileName));

            String first = ins.readLine(); //read from file
            while(first != null){
                System.out.print("Type in a word to follow " + first + ":");
                String second = con.readLine(); //read from console
                //append and write 
                outs.println(first+ ", " + second);
                first = ins.readLine(); //read from file
            }
            ins.close();
            outs.close();
        }
        catch (IOException ex){
            ex.printStackTrace(System.err);
            System.exit(1);
            }

        }
    }
}
user133466
  • 3,391
  • 18
  • 63
  • 92
  • Check http://stackoverflow.com/questions/11224201/exception-in-thread-main-java-lang-error-unresolved-compilation-problems – Ankur Oct 12 '12 at 19:18
  • @Ankur it appears to me that i've accepted answers to all my questions. Idk why it's still at 52%... – user133466 Oct 12 '12 at 19:26
  • @user133466 [Click here](http://stackoverflow.com/users/133466/user133466?tab=questions). The ones with green backgrounds but white text for the answer counts are questions that are answered without an accepted answer. – Brian Oct 12 '12 at 19:29
  • @Brian and user133466, I was just going through the previous questions http://stackoverflow.com/questions/1622323/is-illegal-for-a-struct and http://stackoverflow.com/questions/1598773/is-there-a-standard-function-in-c-that-would-return-the-length-of-an-array which could easily be accepted, thats why I left a comment – Ankur Oct 12 '12 at 19:29
  • @Ankur I see that now :) But 52% is still middle-of-the-road. I'd be more concerned if it were below 40% or 30%. – Brian Oct 12 '12 at 19:30

1 Answers1

1

You appear to have too many braces. You can delete the last } character to make this code compile.

Reimeus
  • 158,255
  • 15
  • 216
  • 276
  • now I have a `Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 at FileTest.main(FileTest.java:48)` – user133466 Oct 12 '12 at 19:20
  • That is a Runtime exception probably caused by not passing in arguments I would guess. As youre using Eclipse, you can supply arguments in Program Arguments in your Run Configuration. – Reimeus Oct 12 '12 at 19:22
  • @Ankur how can i pass a command line argument? I just clicked the "play" button in Eclipse to compile... – user133466 Oct 12 '12 at 19:23
  • @user133466 try this: http://www.cs.colostate.edu/helpdocs/eclipseCommLineArgs.html – Ankur Oct 12 '12 at 19:25
  • Use the "Run configurations" option. There's an "Arguments" tab with a "Program arguments" field. – Brian Oct 12 '12 at 19:25
  • @Brian I've added the argument, but now it's saying "in.txt, (The system cannot find the file specified)" but I'm sure have created a in.txt text file under the source directory .... – user133466 Oct 12 '12 at 19:40
  • Put it under the project root directory, not the source directory. – Brian Oct 12 '12 at 21:08
  • 1
    Hi @Brian, see http://stackoverflow.com/questions/12866146/java-io-filenotfoundexception-in-txt-the-system-cannot-find-the-file-specifie – Reimeus Oct 12 '12 at 21:09