RangeError index out of range

1、错误描述

 

> buffer=new Buffer([0x11,0x22,0x33,0x44,0x55,0x66]);
<Buffer 11 22 33 44 55 66>
> buffer.readUInt8(0);
17
> buffer.readUInt8(1);
34
> buffer.readUInt8(2);
51
> buffer.readUInt8(3);
68
> buffer.readUInt8(4);
85
> buffer.readUInt8(5);
102
> buffer.readUInt8(6);
RangeError: index out of range
    at checkOffset (buffer.js:615:11)
    at Buffer.readUInt8 (buffer.js:653:5)
    at repl:1:8
    at REPLServer.defaultEval (repl.js:262:27)
    at bound (domain.js:287:14)
    at REPLServer.runBound [as eval] (domain.js:300:12)
    at REPLServer.<anonymous> (repl.js:431:12)
    at emitOne (events.js:82:20)
    at REPLServer.emit (events.js:169:7)
    at REPLServer.Interface._onLine (readline.js:211:10)
>

2、错误原因

     超出索引值范围

 

3、解决办法

     由于索引值可以为0、1、2、3、4、5,不能超过5,所以不能出现buffer.readUInt8(6);

再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow

猜你喜欢

转载自www.cnblogs.com/odejsjhshw/p/10373690.html
0条评论
添加一条新回复