isar / hive

Lightweight and blazing fast key-value database written in pure Dart.
Apache License 2.0
4.11k stars 410 forks source link

Error: HiveError: Box not found. Did you forget to call Hive.openBox() #1243

Open divyesh5Gen opened 1 year ago

divyesh5Gen commented 1 year ago

I am getting the following error when I try to open the box tableDeviceShadow in my code:

Error: HiveError: Box not found. Did you forget to call Hive.openBox()

I have already added the await keyword before the Hive.openBox() function, but the error is still occurring.

I have tried the following things to fix the issue:

None of these things have worked.

I am attaching a screenshot of the error message.

I would appreciate any help you can provide in resolving this issue.

Thank you.

image

milindgoel15 commented 1 year ago

Where are you calling the openBox in your app?

divyesh5Gen commented 1 year ago

@milindgoel15 On Crud operation in DB

like: add, update, and get data from db.

milindgoel15 commented 1 year ago

You have to call openBox because the app runs, in the main() function before runApp. And after that you can do crud operation anywhere in the app by creating an instance of created box using Hive.box(boxname)

divyesh5Gen commented 1 year ago

You mean I should open it only once when the app initializes?

milindgoel15 commented 1 year ago

You mean I should open it only once when the app initializes?

yes, it should only be initialised once in the main function.