4 Replies Latest reply on Feb 5, 2003 4:18 PM by 807594

    java.io.IOException: The handle is invalid

    807594
      Please help. i have been trying almost everything for the last 3 days. The code has no syntax errors but when i run it in RealJ IDE, the output is as follows:

      WELCOME TO SHOW CINEMA BOOKING SYSTEM
      PLEASE MAKE SELECTION
      1. AFTERNOON SHOW - 2.00PM
      2. EVENING SHOW - 5.00PM
      3. MAIN SHOW - 8.00PM
      4. LATE SHOW - 11.00PM
      5. EXIT
      java.io.IOException: The handle is invalid
           at java.io.FileInputStream.readBytes(Native Method)
           at java.io.FileInputStream.read(FileInputStream.java:191)
           at java.io.BufferedInputStream.fill(BufferedInputStream.java:183)
           at java.io.BufferedInputStream.read(BufferedInputStream.java:201)
           at Show.main(Show.java:56)
      Exception in thread "main" Exit code: 1
      There were errors


      My source code are as follows:
      import java.io.*;

      public class Show
      {
           private int count;
           private int max;
           
           public Show()
           {
                count = 0;
                max = 0;
           }
           
           public int book(int seats)
           {
                count = (count + seats);
                return seats;
           }
           
           
           
           
                     
           public static void main(String args[]) throws IOException
           {
                Show noon = new Show();
                Show evening = new Show();
                Show mainshow = new Show();
                Show late = new Show();
                int achoice = 0;
                int seats = 0;
           
           
           while (achoice != 5)
           {
                System.out.println("WELCOME TO SHOW CINEMA BOOKING SYSTEM");
                System.out.println("PLEASE MAKE SELECTION");
                System.out.println("1. AFTERNOON SHOW - 2.00PM");
                System.out.println("2. EVENING SHOW - 5.00PM");
                System.out.println("3. MAIN SHOW - 8.00PM");
                System.out.println("4. LATE SHOW - 11.00PM");
                System.out.println("5. EXIT");
                
           
           try{
           achoice = (int)System.in.read();
           }
           catch(NumberFormatException nfe) {
           System.out.println("Numbers only please, try again.");
           }

           
                
                while (achoice != 5 && seats < 1)
                {
                     System.out.println("NUMBER OF SEATS : ");
                BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
                String temp = in.readLine();
                try{

                     seats = Integer.parseInt(temp);
                }
                catch(NumberFormatException nfe) {
                System.out.println("Numbers only please, try again.");
                }
                }
                }
                
                switch(achoice)
                {
                     case 1: noon.book(seats);
                               break;
                     case 2: evening.book(seats);
                               break;
                     case 3: mainshow.book(seats);
                               break;
                     case 4: late.book(seats);
                               break;
                     case 5: break;
                     default: System.out.println("ERROR");
                                    break;
                }
                
                     
                System.out.println("Summary Of Bookings");
                System.out.println("Afternoon Show :" + noon.count);
                System.out.println("Evening Show :" + evening.count);
                System.out.println("Main Show :" + mainshow.count);
                System.out.println("Late Show :" + late.count);
                System.out.println("Total Bookings :" );
           
                                                                                 
           }
      }
        • 1. Re: java.io.IOException: The handle is invalid
          807594
          ow you say, the Bizarre

          try{
          achoice = (int)System.in.read();
          }
          catch(NumberFormatException nfe) {
          System.out.println("Numbers only please, try again.");
          }

          System.in.read() throws IOException!
          • 2. Re: java.io.IOException: The handle is invalid
            807594
            Hi,
            First of all let me tell you that your program expects an input in the first place where you are presenting the show menu. I do not know about the version of RealJ IDE that you are using but the one that I had did not have any provision to give input to the running process through the IDE. It is written in the help section that incase the application requires any input other than ones having a GUI would have to be run using the "Run with Console" option.
            Please click the Build option in the Menu Bar to find the run with console option.
            But there are other inherent problems with the code that you may find out if you try running the program. Do not worry I had faced these problems also.

            If you get too frustrated use this part :
            BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
            String getChoice = in.readLine();
            achoice = Integer.parseInt(getChoice);
            instead of :
            achoice = (int)System.in.read();


            Secondly once you have already taken in the value of seats and if it is more than 0 then your program would never ask for any more seat bookings.

            First of all run the code through the console and you would find out yourself what are the problems. Go ahead and solve then yourself. Happy coding.
            Cheers
            Aviroop
            • 3. Re: java.io.IOException: The handle is invalid
              807594
              thanks a lot. u saved my day! it really works!!
              • 4. Re: java.io.IOException: The handle is invalid
                807594
                thanks a lot Athina & aviroop. Really appreciate it.