- Nov 6, 2004
- 324
- 0
- 0
I was completing an assignment for a java class dealing with user input using InputStreamReader. I'm sorry I don't have the source code to attach (I'm at work).
In a method outside main(), I had planned on inserting the code for the InputStreamReader. I dutifully inserted the statement throws java.io.IOException before the braces enveloping the method body. I kept getting a compiler error indicating the exceptions had to be referenced or something to that effect (again I don't have the code handy to say specifically for which I apologize). When I would put the code for the InputStreamReader in the main() method, and the throws statement before the main() method body I wouldn't get that problem. I had hoped to put the ISR code in a separate method and make calls to that method from within main(). I got it to work fine by putting all the code in the main method, but was just wondering why I was getting that compiler error. My syntax was fine in the code. I can't believe throws statements can only be used in conjunction with main methods, so why is this happening? FWIW I am using jGrasp as the IDE.
Any insight into this is appreciated, I already turned the assignment in, so nobody answering is allowing me to cheat.
Thanks
In a method outside main(), I had planned on inserting the code for the InputStreamReader. I dutifully inserted the statement throws java.io.IOException before the braces enveloping the method body. I kept getting a compiler error indicating the exceptions had to be referenced or something to that effect (again I don't have the code handy to say specifically for which I apologize). When I would put the code for the InputStreamReader in the main() method, and the throws statement before the main() method body I wouldn't get that problem. I had hoped to put the ISR code in a separate method and make calls to that method from within main(). I got it to work fine by putting all the code in the main method, but was just wondering why I was getting that compiler error. My syntax was fine in the code. I can't believe throws statements can only be used in conjunction with main methods, so why is this happening? FWIW I am using jGrasp as the IDE.
Any insight into this is appreciated, I already turned the assignment in, so nobody answering is allowing me to cheat.
Thanks