-2

I have been looking for the answer to this problem for a good while now since it seems most of the times its something simple. I am trying to read line by line of a file and on some instances convert the string into a number. When i write my code the Interger.parseInt simply doesnt work. I have tried everything from changing the scope of the varaible to leaving it as a string then converting after finishing the loop but it simply says Interger in Interger.parseInt cannot be found.

package inputout;
import java.io.*;
import java.util.*;
import static java.lang.Integer.parseInt;

public class readfilebuffer {

    private String Resname;
    private int numberTables;
    private int[] maxpertable;
    private int[] sbm;
    private String[] line4;

    public void readFile1(File fin) throws FileNotFoundException {
        int count = 0;
        try {
            FileReader fileReader = new FileReader(fin);
            BufferedReader bufferedReader = new BufferedReader(fileReader);
            String line;
            while ((line = bufferedReader.readLine()) != null) {
                if(count==0 )
                Resname = line;
                if(count==1)
                    numberTables = Interger.parseInt(line);//Interger here "cannot be found"
            }
            fileReader.close();
            System.out.println(numberTables);
        } catch (IOException e) {
             e.printStackTrace();
        }
    }
}

and at count==1 i have this line being read in 4 and when i print the value in numberTablles is 0.

jww
  • 97,681
  • 90
  • 411
  • 885
Jovis13
  • 21
  • 1
  • 8

3 Answers3

3

Your "Interger" has a typo: it is "Integer" (you have an extra "r" in there).

Kick Buttowski
  • 6,709
  • 13
  • 37
  • 58
Bernard
  • 281
  • 3
  • 11
  • @Jovis13 You really should accept this answer. No better one will be forthcoming, because there isn't a better one. – Jon Kiparsky Oct 12 '14 at 05:28
1

You've just misspelled it. You've typed Interger instead of Integer.

0

Try this ..

public class readfilebuffer {

    public static void main(String[] args) {
        String Resname;
        int numberTables = 0;
        int[] maxpertable;
        int[] sbm;
        String[] line4;
        int temp=0,temp1=0;

        int count = 0;
        try {
            File fin = new File(fin);
            FileReader fileReader = new FileReader(fin);
            BufferedReader bufferedReader = new BufferedReader(fileReader);
            String line;
            while ((line = bufferedReader.readLine()) != null) {

                   numberTables = Integer.parseInt(line);//Interger here "cannot be found"
                   //System.out.println(numberTables);

                   count++;

                   if(count == 1) {
                       temp = numberTables;
                   }

                   if(count == 2) {
                       temp1 = numberTables;               
                   }
            }
            fileReader.close();
            System.out.println(temp1);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

}
Kick Buttowski
  • 6,709
  • 13
  • 37
  • 58
digit
  • 4,479
  • 3
  • 24
  • 43