Results 1 to 5 of 5
  1. #1
    HubrisRex is offline Member
    Join Date
    Feb 2012
    Posts
    3
    Rep Power
    0

    Default Ahoy there! Quick question about I/O and an exception that's throwing me off

    Hey Everyone,
    In a basic programming class and its my first time doing this kind of thing. We're writing a program where users input the details of their birthdate and then the program spits it back out in a particular format. I hope this doesn't come across as trying to get my homework done for me, I'm just struggling with the class and could use some sage advice.

    Here's my code so far:



    import java.io.*;

    public class birthday_printer {

    public static void main (String[] args){

    BufferedReader date_in = new BufferedReader(new InputStreamReader(System.in));

    String selection = "";
    String month = "";


    System.out.print(" What month were you born in?: ");
    try {
    month = date_in.Readline();
    }
    catch (IOException E); {
    }



    }
    }

    Here's the exception I get when compiling:


    javac birthday_printer.java
    birthday_printer.java:22: '{' expected
    catch (IOException E); {
    ^
    birthday_printer.java:28: reached end of file while parsing
    }
    ^
    2 errors

    Which mean I'm missing a '}', right?

    But I can't seem to find it. Is it there and I need to keep looking or am I misunderstanding the exception?


    And is my 'date_in.Readline()' correct? The example we used in class involved numbers only so this has been a bit tough for me to figure out.

    I've read the Java Platform SE 7 about bufferedreaders but, tbh, it was a bit over my head.

    Thank you in advance for any responses!

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,437
    Blog Entries
    7
    Rep Power
    20

    Default Re: Ahoy there! Quick question about I/O and an exception that's throwing me off

    Quote Originally Posted by HubrisRex View Post
    birthday_printer.java:22: '{' expected
    catch (IOException E); {
    Remove that semicolon; it syntactically doesn't belong there and it confuses the compiler.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    HubrisRex is offline Member
    Join Date
    Feb 2012
    Posts
    3
    Rep Power
    0

    Default Re: Ahoy there! Quick question about I/O and an exception that's throwing me off

    Jos,
    Thank you very much. That cleared that exception but now its throwing this:

    javac birthday_printer.java
    birthday_printer.java:20: cannot find symbol
    symbol : method Readline()
    location: class java.io.BufferedReader
    month = date_in.Readline();
    ^
    1 error

    I have a hunch my input part is wrong, but,I'm bit limited in where to go from here. Any thoughts?

  4. #4
    HubrisRex is offline Member
    Join Date
    Feb 2012
    Posts
    3
    Rep Power
    0

    Default Re: Ahoy there! Quick question about I/O and an exception that's throwing me off

    Okay, I think I got it sorted out, thanks for your help.

  5. #5
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,437
    Blog Entries
    7
    Rep Power
    20

    Default Re: Ahoy there! Quick question about I/O and an exception that's throwing me off

    Just to be sure, here's the API documentation: Java Platform SE 6.

    kind regards,

    Jos

    ps. your last error was just a case error; Java is very strict about that.
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. program throwing write exception
    By devish in forum Advanced Java
    Replies: 2
    Last Post: 10-24-2011, 10:01 AM
  2. Program not throwing exception
    By aedara in forum New To Java
    Replies: 3
    Last Post: 06-28-2011, 05:55 AM
  3. Exception throwing
    By andy16 in forum New To Java
    Replies: 9
    Last Post: 06-07-2010, 05:57 PM
  4. Display Message Without Throwing Exception
    By kailashchandra in forum JavaServer Faces (JSF)
    Replies: 0
    Last Post: 09-27-2008, 09:05 AM
  5. throwing Exception
    By bugger in forum New To Java
    Replies: 3
    Last Post: 11-09-2007, 09:35 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •