3

I'v got an exception after I call put() with my data list.
I know that I closed the box before with a reason (deleteAllFiles() must be closed).
How should I open it again? As I see, dataBoxStore is not null after I closed it.

My code:

dataBoxStore = MyObjectBox.builder().androidContext(this).name("DB").build();

dataBoxStore.close();
dataBoxStore.deleteAllFiles();

final Box<Data> areaLocationBox = dataBoxStore.boxFor(Data.class);
areaLocationBox.put(myList);

Exception:

 Caused by: java.lang.IllegalStateException: Store is closed
    at io.objectbox.BoxStore.checkOpen(BoxStore.java:261)
    at io.objectbox.BoxStore.beginTx(BoxStore.java:310)
    at io.objectbox.Box.getWriter(Box.java:107)
    at io.objectbox.Box.put(Box.java:389)
Markus Junginger
  • 6,950
  • 31
  • 52
motis10
  • 2,484
  • 1
  • 22
  • 46

2 Answers2

2

With ObjectBox 1.3 this got simpler. You can use one of the static BoxStore.deleteAllFiles methods without initiating a BoxStore:

BoxStore.deleteAllFiles(context, "DB");
Markus Junginger
  • 6,950
  • 31
  • 52
1
dataBoxStore.put(myList);

Throw the exception of Store is closed while and dataBoxStore is not null.

What I found is to initiate the boxStore again to use it:

dataBoxStore = MyObjectBox.builder().androidContext(this).name("DB").build();

dataBoxStore.close();
dataBoxStore.deleteAllFiles();

dataBoxStore = MyObjectBox.builder().androidContext(this).name("DB").build();
final Box<Data> areaLocationBox = dataBoxStore.boxFor(Data.class);
areaLocationBox.put(myList);
motis10
  • 2,484
  • 1
  • 22
  • 46