try, catch, exception error
I am working on this assignment where I have to import data from a text file, then search the array for certain numbers
Here is what I have so far:
Code:
import java.io.*;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
public class ArrayNum
{
public static void main(String[] args)
{
int search1 = 513;
int search2 = 123;
int search3 = 162;
int search4 = 803;
try
{
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("DATA9.txt")));
String line = null;
while(line == br.read() && line != null)
{
ArrayList NUM = new ArrayList(12);
NUM.add(new Integer(br));
System.out.println("myArrayList contains the following values: " + br);
System.out.println("The number 513 is found at the position(s): " + NUM.indexOf(search1));
System.out.println("The number 123 is found at the position(s): " + NUM.indexOf(search2));
System.out.println("The number 162 is found at the poisition(s): " + NUM.indexOf(search3));
System.out.println("The number 803 is found at the position(s): " + NUM.indexOf(search4));
for(int a = 0; a < br.length; a++)
{
if(NUM.contains(new Integer(a)))
{
System.out.println("The value was found at position: " + NUM[a]);
}
else
{
System.out.println("The value " + "was not found in the array");
}
}
catch(Exception e)
{
System.err.println("There was an error " + e.getMessage());
}
}
}
}
}
It gives me the following errors:
Code:
ArrayNum.java:51: 'catch' without 'try'
catch(Exception e)
ArrayNum.java:51: '}' expected
catch(Exception e)
ArrayNum.java:51: not a statement
catch(Exception e)
ArrayNum.java:51: ';' expected
catch(Exception e)
ArrayNum.java:17: 'try' without 'catch' or 'finally'
try
5 errors
Press any key to continue . . .
Please help!