Error While Working with FirebaseDB in Extension

Declared Varible

private FirebaseDB fb;

In Constructor

fb = FirebaseDB(container);

In Simple Function

fb.FirebaseURL("https://demo-project.firebaseio.com");

I’m getting this error java.lang.NullPointerException: Attempt to invoke virtual method ‘boolean java.lang.String.equals(java.lang.Object)’ on a null object reference while testing extension in companion.

Query: How to solve this error and how to listen for GotValue Event in my extension

1 Like

I’m using Version 1.5.6 Fenix

If so share us your blocks especially when you arr getting this error, i mean On which even get triggered this error arrise pls share us

Latest Version is 1.5B.0

2 Likes

Show the full code of your extension

2 Likes

Code of my extension

package hk.gwio.testextension;

import com.google.appinventor.components.annotations.DesignerComponent;
import com.google.appinventor.components.annotations.DesignerProperty;
import com.google.appinventor.components.annotations.SimpleEvent;
import com.google.appinventor.components.annotations.SimpleFunction;
import com.google.appinventor.components.annotations.SimpleObject;
import com.google.appinventor.components.annotations.SimpleProperty;
import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.runtime.AndroidNonvisibleComponent;
import com.google.appinventor.components.runtime.ComponentContainer;
import com.google.appinventor.components.runtime.EventDispatcher;
import com.google.appinventor.components.runtime.FirebaseDB;

@DesignerComponent(description = "Test extension", version = 1, iconName = "", nonVisible = true, category = ComponentCategory.EXTENSION)
@SimpleObject(external = true)
public class TestExtension extends AndroidNonvisibleComponent {
    private FirebaseDB miDB;

    public TestExtension(ComponentContainer container) {
        super(container.$form());
        miDB = new FirebaseDB(container);
    }


    @SimpleFunction(description = "Set firebase url and token")
    public void firebaseKonfig(String url, String token) {
        miDB.FirebaseURL(url);
        miDB.FirebaseToken(token);
    }
    
}

Well, there is nothing to do with companion version.
You should research about how FirebaseDB actually works in AI2. You called the FirebaseURL property before the DefaultURL. DefaultURL is a hidden property that is called at the time of component initialization automatically by app. If you have not set-ed the DefaultURL then firebaseURL variable remains null that causes the NullPointerException later.

You can make it work like this in your extension :

image

You can read and understand more from here :

3 Likes

Yes, but that is also not enough. He first have to set the default url then the normal url, token and also finally call the “Initialize” function.

2 Likes

Thank you Sumit1334 Xoma

Please enlighten me to access/override GotValue event

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.