Cir*_*all 2 java sockets exception runnable
InputStream in = ClientSocket.getInputStream();
new Thread()
{
public void run() {
while (true)
{
int i = in.read();
handleInput(i);
}
}
}.start();
Run Code Online (Sandbox Code Playgroud)
我正在使用此代码在套接字上侦听新数据并获取:
FaceNetChat.java:37: unreported exception java.io.IOException; must be caught or declared to be thrown
int i = in.read();
^
Run Code Online (Sandbox Code Playgroud)
当我在" run() " 之后添加" throws IOException "时,我得到:
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 {
^
Run Code Online (Sandbox Code Playgroud)
这可能很简单,但我很茫然.我怎么通过这个?
您不能覆盖不引发异常的Runnable.run()接口.您必须在run方法中处理异常.
try {
int i = in.read();
} catch (IOException e) {
// do something that makes sense for your application
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1941 次 |
| 最近记录: |