快捷搜索:

NIO SelectionKey attachment()空指针错误

来源:http://www.shanghai-sourcing.com 作者:真人注册 人气:105 发布时间:2019-10-24
摘要:NIO SelectionKey attachment()空指针错误。NIO SelectionKey attachment()空指针错误。NIO SelectionKey attachment()空指针错误。NIO SelectionKey attachment()空指针错误。很奇怪,后来发现第一次注册时添加了O

NIO SelectionKey attachment()空指针错误。NIO SelectionKey attachment()空指针错误。NIO SelectionKey attachment()空指针错误。NIO SelectionKey attachment()空指针错误。很奇怪,后来发现第一次注册时添加了Object,后来注册时没有添加,导致了空指针错误:

Channel注册到Selector时添加了一个Object:

每次注册都添加Object,就不会有这个错误了:

后来取这个Object:

出现空指针错误:

serverSocketChannel1.register(selector, SelectionKey.OP_ACCEPT, num[0]); 
Exception in thread "main" java.lang.NullPointerException
client.register(selector, SelectionKey.OP_READ, num); 
client.register(selector, SelectionKey.OP_READ);
selectionKey.attachment();

本文由金沙澳门官网55网址发布于真人注册,转载请注明出处:NIO SelectionKey attachment()空指针错误

关键词:

最火资讯