android - JSONObject cannot be cast to com.parse.ParseGeoPoint -
i saving geopoint in jsonobject using:
jsonobject obj=new jsonobject(); jsonarray ja=new jsonarray(); if(lx.size()==0){ toast.maketext(ctx, "no location upload now", toast.length_long).show(); } else{ for(int uq=0;uq<lx.size();uq++){ double latit=lx.get(uq).getlatit(); double longit=lx.get(uq).getlongit(); parsegeopoint pgpoint=new parsegeopoint(latit,longit); ja.put(pgpoint); } try { obj.put("locations",ja); } catch (jsonexception e1) { // todo auto-generated catch block e1.printstacktrace(); }
after sending jsonobject parse cloud.
po.put("historyfile", obj); po.saveinbackground(new savecallback() {
now tried this:
jsonarray locations; parsegeopoint locations = obj.getjsonarray("locations"); (int yx = 0; yx < locations.length(); yx++) { pg =(parsegeopoint)locations.get(yx); //draw geopoint on googlemap }
firstly @ line:
pg =(parsegeopoint)locations.get(yx);
i got error of type mismatch.when typecasted parse object ran fine;but when tried run apk got error:
caused by: java.lang.classcastexception: org.json.jsonobject cannot cast com.parse.parsegeopoint
try go parse.com data page , copy paste jsonobject jsonlint.com, see pg
looks once saved inside jsonobject. string value can treated jsonobject, there no way string, or jsonobject matter can cast directly parsegeopoint. @ best can dive in retrieve lat/lon values:
jsonarray locations; parsegeopoint locations = obj.getjsonarray("locations"); (int yx = 0; yx < locations.length(); yx++) { pg = locations.getjsonobject(yx); double lat = pg.getdouble("latitude") double lon = pg.getdouble("longitude") //draw geopoint on googlemap }
now havent tried save parsegeopoint jsonobject way do, not sure if above correct, example.
if need able store , retrieve location, do:
... for(int uq=0;uq<lx.size();uq++){ double latit=lx.get(uq).getlatit(); double longit=lx.get(uq).getlongit(); jsonobject jsonpos = new jsonobject() json.put("lat", latit); json.put("lon", longit); ja.put(jsonpos); } ...
and
jsonarray locations; parsegeopoint locations = obj.getjsonarray("locations"); (int yx = 0; yx < locations.length(); yx++) { pg =locations.getjsonobject(yx); double lat = pg.getdouble("lat") double lon = pg.getdouble("lon") //draw geopoint on googlemap }
Comments
Post a Comment