Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FlowManager not initialized while init method called. #1300

Closed
goto1134 opened this issue May 24, 2017 · 7 comments
Closed

FlowManager not initialized while init method called. #1300

goto1134 opened this issue May 24, 2017 · 7 comments

Comments

@goto1134
Copy link

goto1134 commented May 24, 2017

I did everything according to the guide: the libraries, the application onCreate method. I've got this error when running the app:

FATAL EXCEPTION: main                                                                                                                                                                                                                                                              
Process: tinkoff.androidcourse, PID: 2981                                                                                                                                                                                                                                          
java.lang.RuntimeException: Unable to start activity ComponentInfo{tinkoff.androidcourse/tinkoff.androidcourse.NavigationActivity}: java.lang.IllegalStateException: The global database holder is not initialized. Ensure you call FlowManager.init() before accessing the databas
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)                                                                                                                                                                                                  
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)                                                                                                                                                                                                   
    at android.app.ActivityThread.-wrap12(ActivityThread.java)                                                                                                                                                                                                                     
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)                                                                                                                                                                                                        
    at android.os.Handler.dispatchMessage(Handler.java:102)                                                                                                                                                                                                                        
    at android.os.Looper.loop(Looper.java:154)                                                                                                                                                                                                                                     
    at android.app.ActivityThread.main(ActivityThread.java:6119)                                                                                                                                                                                                                   
    at java.lang.reflect.Method.invoke(Native Method)                                                                                                                                                                                                                              
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)                                                                                                                                                                                             
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)                                                                                                                                                                                                                
 Caused by: java.lang.IllegalStateException: The global database holder is not initialized. Ensure you call FlowManager.init() before accessing the database.                                                                                                                      
    at a.b.a.a.b.f.c(Unknown Source)                                                                                                                                                                                                                                               
    at a.b.a.a.b.f.b(Unknown Source)                                                                                                                                                                                                                                               
    at a.b.a.a.b.f.i(Unknown Source)                                                                                                                                                                                                                                               
    at a.b.a.a.b.f.a(Unknown Source)                                                                                                                                                                                                                                               
    at a.b.a.a.f.a.e.f(Unknown Source)                                                                                                                                                                                                                                             
    at a.b.a.a.f.a.e.a(Unknown Source)                                                                                                                                                                                                                                             
    at a.b.a.a.f.a.a.b(Unknown Source)                                                                                                                                                                                                                                             
    at a.b.a.a.f.a.d.b(Unknown Source)                                                                                                                                                                                                                                             
    at tinkoff.androidcourse.e.b(Unknown Source)                                                                                                                                                                                                                                   
    at tinkoff.androidcourse.e.a(Unknown Source)                                                                                                                                                                                                                                   
    at android.support.v4.b.l.b(Unknown Source)                                                                                                                                                                                                                                    
    at android.support.v4.b.r.a(Unknown Source)                                                                                                                                                                                                                                    
    at android.support.v4.b.r.d(Unknown Source)                                                                                                                                                                                                                                    
    at android.support.v4.b.r.a(Unknown Source)                                                                                                                                                                                                                                    
    at android.support.v4.b.f.c(Unknown Source)                                                                                                                                                                                                                                    
    at android.support.v4.b.r.b(Unknown Source)                                                                                                                                                                                                                                    
    at android.support.v4.b.r.a(Unknown Source)                                                                                                                                                                                                                                    
    at android.support.v4.b.r.b(Unknown Source)                                                                                                                                                                                                                                    
    at android.support.v4.b.r.f(Unknown Source)                                                                                                                                                                                                                                    
    at android.support.v4.b.o.o(Unknown Source)                                                                                                                                                                                                                                    
    at android.support.v4.b.m.onStart(Unknown Source)                                                                                                                                                                                                                              
    at android.support.v7.app.e.onStart(Unknown Source)                                                                                                                                                                                                                            
    at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1248)                                                                                                                                                                                                  
    at android.app.Activity.performStart(Activity.java:6696)                                                                                                                                                                                                                       
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2628)                                                                                                                                                                                                  
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)                                                                                                                                                                                                   
    at android.app.ActivityThread.-wrap12(ActivityThread.java)                                                                                                                                                                                                                     
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)                                                                                                                                                                                                        
    at android.os.Handler.dispatchMessage(Handler.java:102)                                                                                                                                                                                                                        
    at android.os.Looper.loop(Looper.java:154)                                                                                                                                                                                                                                     
    at android.app.ActivityThread.main(ActivityThread.java:6119)                                                                                                                                                                                                                   
    at java.lang.reflect.Method.invoke(Native Method)                                                                                                                                                                                                                              
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)                                                                                                                                                                                             
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)                                                                                                                                                                                                                                                                                                                                                                                                               

DBFlow:4.0.2
Gradle:2.3.2
buildToolsVersion:25.0.3

Application class is added to manifest.

public class App extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        PrefManager.newInstance(this);
        FlowManager.init(this);
    }
}
@goto1134
Copy link
Author

I found the solution!!! it was all about proguard rules. Please, write about it on the main page. It should be more noticable.

@agrosner
Copy link
Owner

It has its own section on the documentation website....https://agrosner.gitbooks.io/dbflow/content/proguard.html

@adam-hurwitz
Copy link

adam-hurwitz commented Jul 8, 2017

I was receiving the throwable The global database holder is not initialized. Ensure you call FlowManager.init() before accessing the database. I added this line -keep class * extends com.raizlabs.android.dbflow.config.DatabaseHolder { *; } to my proguard-rules.pro

  1. I have the initialization in my Application class.

FlowManager.init(new FlowConfig.Builder(this).build());

  1. I setup my Database.
@Database(name = DoorDashDb.NAME, version = DoorDashDb.VERSION)
public class DoorDashDb extends BaseModel {
    public static final String NAME = "DoorDashDb";
    public static final int VERSION = 1;
}
  1. I created my Table.
@Table(database = DoorDashDb.class)
public class Restaurant extends BaseModel implements Parcelable {
    @Column
    @PrimaryKey
    private int id;

    @Column
    private String name;
...

Because I'm using Kotlin I switched annotationProcessor "com.github.Raizlabs.DBFlow:dbflow-processor:${dbflow_version}" to use kapt and it fixed it.

@azizkayumov
Copy link

azizkayumov commented Aug 24, 2017

I am having the same issue:
My application class contains:
FlowManager.init(new FlowConfig.Builder(applicationContext) .openDatabasesOnInit(true) .build()); FlowLog.setMinimumLoggingLevel(FlowLog.Level.V);

My database:
@Database(name = PagerDatabase.NAME, version = PagerDatabase.VERSION) public class PagerDatabase { public static final String NAME = "PagerDatabase"; public static final int VERSION = 1; }

My table:
@Table(database = PagerDatabase.class) public class PagerContact extends BaseModel{ @Column @SerializedName("id") @Expose private Long id; @Column @PrimaryKey @SerializedName("account_id") @Expose private Long accountId; ........

I added the following to proguard:
-keep class * extends com.raizlabs.android.dbflow.config.DatabaseHolder { *; } -keep class net.sqlcipher.** { *; } -dontwarn net.sqlcipher.**

When I try to save any object, it gives me:
java.lang.RuntimeException: java.lang.IllegalStateException: The global database holder is not initialized. Ensure you call FlowManager.init() before accessing the database.
Is there anything I am missing? Thanks beforehand.

@IonutNegru87
Copy link

IonutNegru87 commented Nov 15, 2017

I'm encountering this issue also.
I have the proguard rules updated like in the documentation, but it is not working.
If I disabled the minification process the app works, thus I suspect the proguard rules to affect the app.

LE: It seems I was misusing some proguard files and I wasn't loading the correct rules for this library.
Seems to work correctly now. Thank you and keep up the good work.

@voghDev
Copy link

voghDev commented Jan 22, 2018

I was having the same issue, using Kotlin. Finally discovered the reason, and it was due to the annotation processor. I didn't add the

apply plugin: 'kotlin-kapt'

in my app/build.gradle, so the database creation was not taking effect by the annotation processor. Similar to #1507.

It works fine now, if someone wants to get the code, it is here, (note the add_dbflow branch)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants