为什么会出现此错误:java.net.PlainSocketImpl.checkNotClosed(PlainSocketImpl.java:116)?

时间:2016-12-30 20:54:56

标签: java android sockets networking

我正在使用Android上的套接字并继续收到此错误

logcat的:

[xiaomi-mi_4i-a98ed4b2]: E/File couldn't be stored: java.net.PlainSocketImpl.checkNotClosed(PlainSocketImpl.java:116)
[xiaomi-mi_4i-a98ed4b2]: W/System.err: java.net.SocketException: Socket is closed
[xiaomi-mi_4i-a98ed4b2]: W/System.err:     at java.net.PlainSocketImpl.checkNotClosed(PlainSocketImpl.java:116)
[xiaomi-mi_4i-a98ed4b2]: W/System.err:     at java.net.PlainSocketImpl.getInputStream(PlainSocketImpl.java:213)
[xiaomi-mi_4i-a98ed4b2]: W/System.err:     at java.net.Socket.getInputStream(Socket.java:363)
[xiaomi-mi_4i-a98ed4b2]: W/System.err:     at com.rkp.musictest1.wifi.datatransfer.WifiSocket.receiveFileSocket(WifiSocket.java:264)
[xiaomi-mi_4i-a98ed4b2]: W/System.err:     at com.rkp.musictest1.wifi.datatransfer.WifiSocket$4.run(WifiSocket.java:249)
[xiaomi-mi_4i-a98ed4b2]: W/System.err:     at com.rkp.musictest1.wifi.datatransfer.SimpleAsynTask$simpleTask.doInBackground(SimpleAsynTask.java:65)
[xiaomi-mi_4i-a98ed4b2]: W/System.err:     at com.rkp.musictest1.wifi.datatransfer.SimpleAsynTask$simpleTask.doInBackground(SimpleAsynTask.java:23)
[xiaomi-mi_4i-a98ed4b2]: W/System.err:     at android.os.AsyncTask$2.call(AsyncTask.java:288)
[xiaomi-mi_4i-a98ed4b2]: W/System.err:     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
[xiaomi-mi_4i-a98ed4b2]: W/System.err:     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
[xiaomi-mi_4i-a98ed4b2]: W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
[xiaomi-mi_4i-a98ed4b2]: W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
[xiaomi-mi_4i-a98ed4b2]: W/System.err:     at java.lang.Thread.run(Thread.java:818)

1 个答案:

答案 0 :(得分:3)

您可以自己查看源代码 - 它是enter link description here

private void More ...checkNotClosed() throws IOException {
    if (!fd.valid()) {
        throw new SocketException("Socket is closed");
    }
}

fd是一个FileDescriptor;为此,我们发现;关于valid()方法:

返回: 如果文件描述符对象表示有效的,打开的文件,套接字或其他活动I / O连接,则为true;否则为false。否则就是假。

所以,长话短说:关闭的东西不应该被关闭。但进一步的调试是 hard 而没有看到导致此错误的代码/活动。

希望这足以让你现在开始!