java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare() getting runtime error in android -
getting runtimeexception
in android :
java.lang.runtimeexception: can't create handler inside thread has not called looper.prepare() getting run time error @ toast.maketext(this, latitude+""+longitude, 1).show();
in function updatelocation()
.
public class location_update extends service { double latitude; double longitude; gpslocation gps; boolean state=true; @override public ibinder onbind(intent intent) { // todo auto-generated method stub return null; } @override public void oncreate() { // todo auto-generated method stub super.oncreate(); timer timer = new timer(); timer.schedule(task, 0,1000*30); } timertask task=new timertask() { @override public void run() { // todo auto-generated method stub updatelocation(); } }; public void updatelocation() { gps = new gpslocation(mainactivity.dis); // check if gps enabled if(gps.cangetlocation()){ latitude = gps.getlatitude(); longitude = gps.getlongitude(); try { toast.maketext(this, latitude+""+longitude, 1).show(); } catch(exception e) { log.d("error", "msg:-- "+e); } // \n new line //toast.maketext(location_update.this, "your location - \nlat: " + latitude + "\nlong: " + longitude, toast.length_long).show(); }else{ // can't location // gps or network not enabled // ask user enable gps/network in settings gps.showsettingsalert(); } if(gps.getlatitude()!=0.0 && gps.getlongitude()!=0.0) { try { string url = "http://surajsingh.freetzi.com/insert_longi_latti.php?latti="+latitude+"&longi="+longitude; httpget = new httpget(url); defaulthttpclient httpclient = new defaulthttpclient(); httpresponse httpresponse = httpclient.execute(get); httpentity httpentity = httpresponse.getentity(); string data = entityutils.tostring(httpentity); jsonobject obj = new jsonobject(data); int status = obj.getint("status"); } catch (exception e) { // todo: handle exception // toast.maketext(location_update.this, ""+e, 1).show(); log.d("error", ""+e); } } } }
you're calling worker thread. need call toast.maketext() within main thread. use handler.
Comments
Post a Comment