Attempt to invoke virtual method com.google.firebase.remoteconfig com.google.firebase.remoteconfig.RemoteConfigComponent.getDefault() on a null object

Viewed 210

I try to use Firebase remote config and I follow all steps , but when I open the app it crashes and tell me this error:

java.lang.NullPointerException: Attempt to invoke virtual method 'com.google.firebase.remoteconfig.FirebaseRemoteConfig com.google.firebase.remoteconfig.RemoteConfigComponent.getDefault()' on a null object reference

And this is my code :

private void initializeLogic() {
    final FirebaseRemoteConfig mFirebaseRemoteConfig;
    mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance();
    FirebaseRemoteConfigSettings configSettings = new FirebaseRemoteConfigSettings.Builder()
    .setMinimumFetchIntervalInSeconds(3600)
    .build();
    mFirebaseRemoteConfig.setConfigSettingsAsync(configSettings);
    mFirebaseRemoteConfig.setDefaultsAsync(R.drawable.remote_config_defaults);
    mFirebaseRemoteConfig.fetchAndActivate()
    .addOnCompleteListener(this, new OnCompleteListener<Boolean>() {
        @Override
        public void onComplete(@NonNull Task<Boolean> task) {
            if (task.isSuccessful()) {
                boolean updated = task.getResult();
                Toast.makeText(MainActivity.this, "Fetch and activate succeeded",Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(MainActivity.this, "Fetch failed",Toast.LENGTH_SHORT).show();
            }
            
        }
    });
}

And I create remote_config_defaults.xml and I put it in drawable folder

How to solve this problem please help. Note : I added the parameter in firebase console with the same key in remote_config_defaulte.xml

0 Answers
Related