android - When I click start button for proximity responce It crashes my app -
when click on button, calls setproximityalert()
function, , toast displayed. not understand problem is,
@override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.locations); button start = (button) findviewbyid(r.id.startl); start.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { setproximityalert(); toast.maketext(getbasecontext(), "started", toast.length_long).show(); } }); } private static final string mmh_proximity_alert = "com.example.proximityalert"; private void setproximityalert() { cursor c = db.rawquery("select * locations", null); double lng = c.getdouble(c.getcolumnindex("longitude")); c.movetonext(); double lat = c.getdouble(c.getcolumnindex("latitude")); c.movetonext(); float rds = c.getfloat(c.getcolumnindex("radius")); c.movetonext(); string locservice = context.location_service; locationmanager locationmanager; locationmanager = (locationmanager)getsystemservice(locservice); long expiration = -1; // not expire intent intent = new intent(mmh_proximity_alert); pendingintent proximityintent = pendingintent.getbroadcast(this, -1, intent, 0); locationmanager.addproximityalert(lat, lng, rds, expiration, proximityintent); c.close(); locationmanager.addproximityalert( lat, // latitude of central point of alert region lng, // longitude of central point of alert region rds, // radius of central point of alert region, in meters expiration, // time proximity alert, in milliseconds, or -1 indicate no expiration proximityintent // used generate intent fire when entry or exit alert region detected ); intentfilter filter = new intentfilter(mmh_proximity_alert); registerreceiver(new proximityintentreceiver(), filter); }
use movetofirst
method on cursor before try access data.
Comments
Post a Comment