g037a
(g037a)
July 22, 2022, 9:52am
#1
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
g037a
(g037a)
July 22, 2022, 12:40pm
#3
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
Shreyaa
(shreya )
July 22, 2022, 1:40pm
#6
g037a:
my extension
Show the full code of your extension
2 Likes
g037a
(g037a)
July 22, 2022, 2:28pm
#7
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);
}
}
iamwsumit
(Sumit Kumar)
July 22, 2022, 4:35pm
#8
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 :
You can read and understand more from here :
* @param url the URL for the Firebase
*/
@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_FIREBASE_URL,
defaultValue = "DEFAULT")
@SimpleProperty(description = "Sets the URL for this FirebaseDB.")
public void FirebaseURL(String url) {
if (url.equals("DEFAULT")) {
if (!useDefault) { // If we weren't setup for the default
useDefault = true;
if (defaultURL == null) { // Not setup yet
Log.d(LOG_TAG, "FirebaseURL called before DefaultURL (should not happen!)");
} else {
firebaseURL = defaultURL;
resetListener();
}
} else {
firebaseURL = defaultURL; // Should already be the case
}
} else {
useDefault = false;
url = url + (url.endsWith("/") ? "" : "/");
3 Likes
Xoma
(Kumaraswamy)
July 22, 2022, 4:59pm
#9
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.
* We cannot make a connection to Firebase in the component
* Constructor because we do not yet know the value of the
* Persist property. The Persist property is used to set the
* persistance flag in the Firebase static config. It must
* be set prior to any connection happening and cannot be
* changed after a Firebase connection (or reference) is made.
* So we defer making a connection until we initialize. Initialize
* is called from runtime.scm (via Form.java) after all components
* and properties have been setup.
*/
public void Initialize() {
Log.i(LOG_TAG, "Initalize called!");
isInitialized = true;
resetListener();
}
/**
* Getter for the Firebase URL.
*
* @return the URL for this Firebase
*/
2 Likes
g037a
(g037a)
July 22, 2022, 5:48pm
#10
Thank you Sumit1334 Xoma
Please enlighten me to access/override GotValue event
system
(system)
Closed
August 21, 2022, 5:48pm
#11
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.