RangeError index out of range

Posted odejsjhshw

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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


以上是关于RangeError index out of range的主要内容,如果未能解决你的问题,请参考以下文章

Index was out of range

Pytorch 错误“RuntimeError: index out of range: 试图访问索引 512 out of table with 511 rows”

list assignment index out of range

xadmin:list index out of range

Python常见错误:IndexError: list index out of range

list index out of bounds