objectbox / objectbox-java

Android Database - first and fast, lightweight on-device vector database
https://objectbox.io
Apache License 2.0
4.36k stars 301 forks source link

BoxStoreBuilder IllegalStateException #980

Closed ghostteamo closed 3 years ago

ghostteamo commented 3 years ago

When i create the dbTable, invoke the method created by code BoxStore boxStore = MyObjectBox.builder().name(dbName).androidContext(IhApplication.getContext()).build(); i got a crash,

version: '2.7.1'

Caused by: java.lang.IllegalStateException: at io.objectbox.BoxStoreBuilder.getAndroidFilesDir (BoxStoreBuilder.java:274) at io.objectbox.BoxStoreBuilder.getAndroidBaseDir (BoxStoreBuilder.java:252) at io.objectbox.BoxStoreBuilder.androidContext (BoxStoreBuilder.java:202) at xx.initializer.CacheApplicationInitializer.objectBoxInitialize (CacheApplicationInitializer.kt:48) at xx.context.initializer.CacheApplicationInitializer.initialize (CacheApplicationInitializer.kt:32) at xx.onCallApplicationInitializer (BaseApp.kt:73) at xx.onCreate (BaseApp.kt:60) at android.app.Instrumentation.callApplicationOnCreate (Instrumentation.java:1190) at android.app.ActivityThread.handleBindApplication (ActivityThread.java:6909)

also

Caused by: java.lang.IllegalStateException: at io.objectbox.d.c (BoxStoreBuilder.java:6) at io.objectbox.d.b (BoxStoreBuilder.java:6) at io.objectbox.d.a (BoxStoreBuilder.java:2) at xx.initializer.CacheApplicationInitializer.objectBoxInitialize (CacheApplicationInitializer.kt:48) at xx.context.initializer.CacheApplicationInitializer.initialize (CacheApplicationInitializer.kt:32) at xx.onCallApplicationInitializer (BaseApp.kt:73) at xx.onCreate (BaseApp.kt:60) at android.app.Instrumentation.callApplicationOnCreate (Instrumentation.java:1208) at android.app.ActivityThread.handleBindApplication (ActivityThread.java:6986)

image

is there any solutions?

greenrobot-team commented 3 years ago

Look at the line that is throwing the error: https://github.com/objectbox/objectbox-java/blob/V2.7.1/objectbox-java/src/main/java/io/objectbox/BoxStoreBuilder.java#L274 Error message is "Android files dir does not exist".

Try to check if your code can access context.getFilesDir() and that it exists.

The second stacktrace is obfuscated, I can't help you with that.

no-response[bot] commented 3 years ago

Without additional information, we are unfortunately not sure how to resolve this issue. Therefore this issue has been automatically closed. Feel free to comment with additional details and we can re-open this issue.