Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unreported excep. IOException must be caught or declared to be thrown

Status
Not open for further replies.

garishnikov

Programmer
Mar 20, 2003
6
AU
I'm getting this message when trying to compile. This is what the code in question looks like:

import java.io.*;

public class User

{

String userName;
String userHand;
int handNumber;
String choice;

public User() throws IOException

{

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

System.out.println();
System.out.println("Welcome to RPS. What is your name?");
userName = theInput.readLine();
}
}

Any ideas?? Thanks
 
Hi garishnikov,

I cut and pasted your code and it compiled fine for me.

scrat
 
Hi garishnikov:

I copy pasted it too and it worked. This is my Java version:

java version "1.3.1_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1_02-b02)
Java HotSpot(TM) Client VM (build 1.3.1_02-b02, mixed mode)

I think that your jvm version could be the reason.

Hope it helps.
Pedro Andrés Solorzano
Pontificia Universidad Javeriana
Bogotá, Colombia, SurAmérica.
 
I will guess that somewhere in your project you have another .java file with a main() method, and in that method you have something like:

Code:
User myUser = new User();

So the User constructor is defined to throw an exception and the calling code is not handling the exception. The calling fuction being main(). So either change the signature of main to throw the exception or put the User construction code into a try/catch block

Code:
public int main(...) throws Exception
{
  User myUser = new User();
}

-pete

 
Thanks guys,

Figured it out after getting up and coming back to it later. Thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top