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!
Re: Ahoy there! Quick question about I/O and an exception that's throwing me off
Quote:
Originally Posted by
HubrisRex
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
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?
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.
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.