android - com.firebase.client.FirebaseException: Failed to bounce to type JSON -
i have code here..
main_menu.java
@override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main_menu); getdata(); } private void getdata(){ string url = config.data_url+a_username; requestqueue requestqueue = volley.newrequestqueue(this); log.d(tag,"merging url , name success"); stringrequest stringrequest = new stringrequest(request.method.get, url, new response.listener<string>() { @override public void onresponse(string response) { showjson(response); log.d(tag,"show json success"); } }, new response.errorlistener() { @override public void onerrorresponse(volleyerror error) { } }); requestqueue.add(stringrequest); } private void showjson(string response){ try { jsonobject jsonobject = new jsonobject(response); jsonarray result = jsonobject.getjsonarray(config.json_array); jsonobject userid = result.getjsonobject(0); id = userid.getstring(config.key_id).tostring().trim(); toast.maketext(getapplicationcontext(),id,toast.length_long).show(); log.d(tag,"getting id success"); } catch (jsonexception e) { e.printstacktrace(); } } @override protected void onstart(){ super.onstart(); real_id = id.tostring(); mref = new firebase("https://connection-4f6d8.firebaseio.com/"+real_id); mref.addvalueeventlistener(new valueeventlistener() { @override public void ondatachange(datasnapshot datasnapshot) { string text = datasnapshot.getvalue(string.class); if(text.equals("unlocked")){ senddataonwifi("0"); } } @override public void oncancelled(firebaseerror firebaseerror) { } }); }
execption:
fatal exception: main process: com.example.jaypeetan.mftis, pid: 32112com.firebase.client.firebaseexception: failed bounce type @ com.firebase.client.datasnapshot.getvalue(datasnapshot.java:185) @ com.example.jaypeetan.mftis.main_menu$6.ondatachange(main_menu.java:290) @ com.firebase.client.core.valueeventregistration.fireevent(valueeventregistration.java:56) @ com.firebase.client.core.view.dataevent.fire(dataevent.java:45) @ com.firebase.client.core.view.eventraiser$1.run(eventraiser.java:38) @ android.os.handler.handlecallback(handler.java:733) @ android.os.handler.dispatchmessage(handler.java:95) @ android.os.looper.loop(looper.java:149) @ android.app.activitythread.main(activitythread.java:5257) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:515) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:793) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:609) @ dalvik.system.nativestart.main(native method) caused by: com.fasterxml.jackson.databind.jsonmappingexception: can not deserialize instance of java.lang.string out of start_array token @ [source: java.io.stringreader@22c79a40; line: 1, column: 1] @ com.fasterxml.jackson.databind.deserializationcontext.mappingexception(deserializationcontext.java:575) @ com.fasterxml.jackson.databind.deser.std.stringdeserializer.deserialize(stringdeserializer.java:46) @ com.fasterxml.jackson.databind.deser.std.stringdeserializer.deserialize(stringdeserializer.java:11) @ com.fasterxml.jackson.databind.objectmapper._readmapandclose(objectmapper.java:2888) @ com.fasterxml.jackson.databind.objectmapper.readvalue(objectmapper.java:2034) @ com.firebase.client.datasnapshot.getvalue(datasnapshot.java:183) ... 13 more
i believe error json need user id in database im getting correctly problem when tried connect in firebase giving me error.. tried change variable real_id value number , working when depends on json gives me error.. please me :d
you store mix of string
numbers in same list. in code ask string:
// fails when snapshot value number string text = datasnapshot.getvalue(string.class);
that won't work, since number not string (even though can converted one).
if insist on mixing types, code extracts value must able handle mixed types. example:
public void ondatachange(datasnapshot datasnapshot) { string text = string.valueof(datasnapshot.getvalue());
by using datasnapshot.getvalue()
without type, whatever type stored in snapshot. convert string string.valueof()
.
i recommend sticking single uniform type in list. it'll make code less error prone , easier understand.
Comments
Post a Comment