IndexOutOfBoundsException with DatagramChannel.receive(buf);
问题 I'm a complete noob when it comes to networking programming. I'm getting the following error: E/AndroidRuntime( 4095): Caused by: java.lang.IndexOutOfBoundsException: length=18, offset=0, buffer size=0 At the following line: SocketAddress servaddr = udpChannel.receive(rcvHskBuf); This is how I create the buffer ByteBuffer rcvHskBuf = ByteBuffer.allocateDirect(packetSize); For the sake of debugging I changed the argument (which can be changed in the app) from the default 1432 to 1432*20 as