Question:

Help! Error is: Exception in thread "main" java.lang.Error: Unresolved compilation problems:

by  |  earlier

0 LIKES UnLike

Syntax error on token "catch", for expected

Syntax error, insert "; ; ) Statement" to complete ForStatement

Code section below but if you would like I can email to any one who would love to help me! :)

private static void createInputFile() throws IOException

{

inputList = new ArrayList<Integer>();

int value;

input = new FileInputStream("EvenNums.txt");

while ((value = input.read()) != -0)

inputList.add(value);

{

new PrintStream(output).println();

input.close(); // Close output stream

}

catch (IOException e); // Catches any error conditions

{

System.err.println ("Unable to write file");

System.exit(-1);}

}

 Tags:

   Report

3 ANSWERS


  1. I&#039;m not really sure exactly what the intent of your code is, but I have modified it so it compiles without errors. A catch block must be preceded by a try statement. A few comments here and there also help improve the readability and clarity of your code.

    import java.io.FileInputStream;

    import java.io.FileNotFoundException;

    import java.io.IOException;

    import java.io.PrintStream;

    import java.util.ArrayList;

    (...)

    /**

    * Reads the contents of a file into an ArrayList

    */

    private static void createInputFile() {

    ArrayList&lt;Integer&gt; inputList = new ArrayList&lt;Integer&gt;();



    FileInputStream input = null;

    try {

      input = new FileInputStream(&quot;EvenNums.txt&quot;);

      int value;

      while ((value = input.read()) != -1) {

       inputList.add(value);

      }

      input.close();

    } catch (FileNotFoundException e) {

      System.err.println(&quot;Error opening file: &quot; + e.getMessage());

      try {

       input.close();

      } catch (Exception eIgnore) {}

      return;

    } catch (IOException e) {

      System.err.println(&quot;File error: &quot; + e.getMessage());

      try {

       input.close();

      } catch (Exception eIgnore) {}

      return;

    }

    }

    (...)


  2. The biggest thing that bugs my is that catch.....

    Get rid of the simcolon

    catch (IOException e); // Catches any error conditions

    to

    catch (IOException e) // Catches any error conditions

    The curlybraces already encapsulate the catch....

    Are you importing the proper libraries....

    import java.io.*;

    import java.util.ArrayList;

    Do you have enough curly braces at the end...

  3. Go to this site it is for Microsoft products only. There may be an answer there to help you.  

Question Stats

Latest activity: earlier.
This question has 3 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.
Unanswered Questions