1 2 Previous Next 16 Replies Latest reply on Oct 15, 2007 9:36 AM by 807605

    HELP!! ERROR IN reading from file!! (PART of )PROGRAM

    807605
      Take a look at my program first....

      import java.io.*;

      public class reading_file {
      public static void main(String[] args) throws IOException {
      BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
      String [] sType= new String[10];
      int [] sNum= new int[10];
      float [] sPrice= new float[10];

      String FileName="new.txt";

      BufferedReader inFile=new BufferedReader(new FileReader(FileName));

      String inputLine="";
      int totalLines=0;
      while(inFile.readLine()!=null){
      totalLines++;
      }
      int totalStock=totalLines/3;
      System.out.println(totalStock);


      for(int i=0; i<totalStock;i++){
      sType=inFile.readLine();
      System.out.println(sType[i]);
      sNum[i] =Integer.parseInt(inFile.readLine());
      System.out.println(sNum[i]);
      sPrice[i] =Float.parseFloat(inFile.readLine());
      System.out.println(sPrice[i]);
      }
      inFile.close();
      }
      }

      I am reading the info from the file to the respective array shown.
      e.g these are the info in the .txt file
      /////=>
      PANTS
      35
      23.3
      LOGITECH CORDLESS DESKTOP
      200
      50.23
      MONITER
      62
      54.9
      <=

      but when i run the program the errors such as :
      ==>
      compile-single:
      run-single:
      3
      null
      Exception in thread "main" java.lang.NumberFormatException: null
      at java.lang.Integer.parseInt(Integer.java:415)
      at java.lang.Integer.parseInt(Integer.java:497)
      at reading_file.main(reading_file.java:26)
      Java Result: 1
      BUILD SUCCESSFUL (total time: 0 seconds)


      why is that??
      any mistake in the program??
        1 2 Previous Next