vivek yadav
vivek yadav

Reputation: 1547

RangeError (index): Index out of range: no indices are valid: 0

I got this when I was using Hive Database in Flutter. Find out answer below

Upvotes: 13

Views: 20133

Answers (4)

Amo Oniani
Amo Oniani

Reputation: 55

you should give an initializer for example if you want to give an array you should set a default value for example :

List<dynamic> _users = [];

this return error

but if you do this your problem will be solved :

List<dynamic> _users = [
 {
  "id":"",
  "name":"",
  "Phone":""
 }
]

depends on your data that fields

Upvotes: 1

Yash Zade
Yash Zade

Reputation: 163

problem for me was, I am accessing the empty list with index.

ex:

list=[ ] //this is empty list

list[0] // error, because I am accessing empty list.

Upvotes: 6

vivek patel
vivek patel

Reputation: 95

I was getting the same error. when I was trying to add data into hive database using putAt(), but from documantion i found out that putAt() can only be used for the existing index. so switch putAt() instruction with add(). That solved the error.

I know the question is old, but I hope it could help someone.

Upvotes: 6

vivek yadav
vivek yadav

Reputation: 1547

So whenever you get this kind of Error!

Check if whatever you are saving in Hive Database is not null. I got this error while I was storing null object to database.

Upvotes: 0

Related Questions