Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: calling on subroutines with a IOE execption.

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    1
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default calling on subroutines with a IOE execption.

    Hi
    I only started studying java as a curiousity thing 3 months ago. Naturally i'm intreaged an i'm really enjoying it but the online corse is really vage as to a lot of things. My current assignment is to create a database for a sports team. he says that we have to be able to save and load the information in the program. I should also note the entire thing is in Holts Ready to program. Here is the menu:

    int choice;
                do 
                {
                c.println("1.Enter player data");
                c.println("2.Vew players by last name");
                c.println("3.Veiw players by points");
                c.println("4.Add another player"); 
                c.println("5.Deleate a player");
                c.println("6.Modify a player");
                c.println("7.FInd a player by any feild");
                c.println("8.Save data");
                c.println("9.Load previous data");
                c.println("What is it that you would like to do?");
                choice=c.readInt();
                if (choice==1)EnterData();
                if (choice==2)LastName();
                if (choice==3)Points();
                if (choice==4)AddPlayer();
                if (choice==5)Deleate();
                if (choice==6)Modify();
                if (choice==8)saving(); 
                if (choice==9)Loading();
            }
            while (choice!=10);
        }
    for Loading and saving it is telling becasue I use IOException i need to "enclose the subroutine in a try statement that catches the exception or declare that this subroutine throws the excption" nither of witch i understnd below is the two subroutines themselves:
         public static void saving() throws IOException
         {
            int Y;
            PrintWriter fileoutput,FileOutput;
            fileoutput=new PrintWriter(new FileWriter("Playered.txt"));
            fileoutput.println(Players);
            for (Y=1;Y<=Players;Y++)
            {
                fileoutput.print(Playered[Y][1]);
                fileoutput.print(Playered[Y][2]);
                fileoutput.print(Playered[Y][3]);
                fileoutput.print(Numbers[Y][1]);
                fileoutput.print(Numbers[Y][2]);
             }
        }
        public static void Loading()throws IOException
        {
        String line;
        int Y,Lines;
        BufferedReader fileinput;
        fileinput= new BufferedReader(new FileReader("playered.text"));
        line=fileinput.readLine();
        Players=Integer.valueOf(line).intValue();
        c.print(Players);
        for (Y=1;Y<=Players;Y++)
        {
        Playered[Y][1]=fileinput.readLine();
        Playered[Y][2]=fileinput.readLine();
        Playered[Y][3]=fileinput.readLine();
        Numbers[Y][1]=Integer.valueOf(line).intValue();
        Numbers[Y][2]=Integer.valueOf(line).intValue();
        c.println("reading the record for: "+Playered[Y][1]);
        c.println("reading the record for: "+Playered[Y][2]);
        c.println("reading the record for: "+Playered[Y][3]);
        c.println("reading the record for: "+Numbers[Y][1]);
        c.println("Reading the record for: "+Numbers[Y][2]);
        }
        fileinput.close();
        }

    As you can see my program uses subroutines that are both strings and Integer nested arrays. I'm not shure if this matters but it beats forgetting something. Thanks
    littlemissparadox


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,210
    Thanks
    52
    Thanked 2,294 Times in 2,265 Posts

    Default Re: calling on subroutines with a IOE execption.

    need to "enclose the subroutine in a try statement that catches the exception
    or declare that this subroutine throws the excption"
    Take a look at the tutorial:
    Lesson: Exceptions (The Java™ Tutorials > Essential Classes)
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Calling upon methods
    By jonathanfox in forum Java Theory & Questions
    Replies: 4
    Last Post: August 3rd, 2012, 11:58 AM
  2. about calling sub class
    By pokuri in forum Object Oriented Programming
    Replies: 3
    Last Post: January 11th, 2011, 02:30 PM
  3. [SOLVED] method calling
    By javapenguin in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 4th, 2010, 01:43 AM
  4. calling SingleFrameApplication
    By petem86 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 8th, 2010, 09:06 AM
  5. calling a constructor
    By turnwellm in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 3rd, 2010, 07:46 PM