InputStream in = ClientSocket.getInputStream();
new Thread()
{
public void run() {
while (true)
{
int i = in.read();
handleInput(i);
}
}
}.start();
I’m listening to new data on a socket with this code and get:
FaceNetChat.java:37: unreported exception java.io.IOException; must be caught or declared to be thrown
int i = in.read();
^
When I add “throws IOException” after the “run()” I get:
FaceNetChat.java:34: run() in cannot implement run() in java.lang.Runnable; overridden method does not throw java.io.IOException
public void run() throws IOException {
^
It’s probably something simple, but I’m at a loss. How do I get passed this?
You can’t override the interface of Runnable.run() which does not throw an exception. You must instead handle the exception in the run method.