java - NoSuchMethodException on Firebase.setAndroidContext() -
my application isn't able start. firebase.setandroidcontext()
in oncreate()
method causing nosuchmethodexception. see below:
protected firebase ref; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); string firebaseurl = getresources().getstring(r.string.firebase_url); firebase.setandroidcontext(getapplicationcontext()); ref = new firebase(firebaseurl); }
i setup application:
public class firebaseapplication extends application { @override public void oncreate() { super.oncreate(); firebase.setandroidcontext(this); } }
which leads next stacktrace logcat:
i/sf_frame_dur( 60): [com.android.launcher/com.android.launcher2.launcher,0,0,0,20,42,40,20] d/androidruntime(14165): shutting downwards vm e/androidruntime(14165): fatal exception: main e/androidruntime(14165): process: com.github.r351574nc3.earshot, pid: 14165 e/androidruntime(14165): java.lang.assertionerror: impossible e/androidruntime(14165): @ java.lang.enum$1.create(enum.java:45) e/androidruntime(14165): @ java.lang.enum$1.create(enum.java:35) e/androidruntime(14165): @ libcore.util.basiclrucache.get(basiclrucache.java:54) e/androidruntime(14165): @ java.lang.enum.getsharedconstants(enum.java:211) e/androidruntime(14165): @ java.lang.class.getenumconstants(class.java:1029) e/androidruntime(14165): @ com.fasterxml.jackson.databind.cfg.mapperconfig.collectfeaturedefaults(mapperconfig.java:73) e/androidruntime(14165): @ com.fasterxml.jackson.databind.cfg.mapperconfigbase.<clinit>(mapperconfigbase.java:28) e/androidruntime(14165): @ com.fasterxml.jackson.databind.objectmapper.<init>(objectmapper.java:433) e/androidruntime(14165): @ com.fasterxml.jackson.databind.objectmapper.<init>(objectmapper.java:364) e/androidruntime(14165): @ com.firebase.client.firebase.<clinit>(firebase.java:41) e/androidruntime(14165): @ com.firebase.client.firebase.setandroidcontext(firebase.java:860) e/androidruntime(14165): @ com.github.r351574nc3.earshot.earshotapplication.oncreate(earshotapplication.java:11) e/androidruntime(14165): @ android.app.instrumentation.callapplicationoncreate(instrumentation.java:1008) e/androidruntime(14165): @ android.app.activitythread.handlebindapplication(activitythread.java:4397) e/androidruntime(14165): @ android.app.activitythread.access$1500(activitythread.java:143) e/androidruntime(14165): @ android.app.activitythread$h.handlemessage(activitythread.java:1317) e/androidruntime(14165): @ android.os.handler.dispatchmessage(handler.java:102) e/androidruntime(14165): @ android.os.looper.loop(looper.java:135) e/androidruntime(14165): @ android.app.activitythread.main(activitythread.java:5070) e/androidruntime(14165): @ java.lang.reflect.method.invoke(native method) e/androidruntime(14165): @ java.lang.reflect.method.invoke(method.java:372) e/androidruntime(14165): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:836) e/androidruntime(14165): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:631) e/androidruntime(14165): caused by: java.lang.nosuchmethodexception: values [] e/androidruntime(14165): @ java.lang.class.getmethod(class.java:664) e/androidruntime(14165): @ java.lang.class.getdeclaredmethod(class.java:626) e/androidruntime(14165): @ java.lang.enum$1.create(enum.java:41) e/androidruntime(14165): ... 22 more
from stacktrace, can see code causing crash firebase.setandroidcontext(getapplicationcontext());
am doing wrong here? examples use, i'm kinda confused.
as mentioned in firebase api docs, firebase should initialized before firebase reference created or used. should utilize setandroidcontext
method in application's oncreate()
method. should create own application class this:
public class firebaseapplication extends android.app.application { @override public void oncreate() { super.oncreate(); firebase.setandroidcontext(this); } }
then add together name of application
tag in androidmanifest
:
<application android:name="your.package.name.firebaseapplication" //android:icon, android:label, android:theme, etc. ... > ... </application>
and can utilize firebase
in activities:
protected firebase ref; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); string firebaseurl = getresources().getstring(r.string.firebase_url); ref = new firebase(firebaseurl); }
edit:
so don't know what's problem, cause able build project firebase, in example. found 1 thing, may helpful you. seek add together next lines proguard-rules.pro
:
# enumeration classes, see http://proguard.sourceforge.net/manual/examples.html#enumerations -keepclassmembers enum * { public static **[] values(); public static ** valueof(java.lang.string); }
java android firebase
No comments:
Post a Comment