java - app crash when reading SharedPreferences Android -
i can't figure out problem is. code works fine when don't call getprefsgps() method.
the method geocoding location working 2 days ago stopped showing city name...again don't know why! here code
import java.io.ioexception; import java.util.list; import java.util.locale; import android.app.activity; import android.content.context; import android.content.intent; import android.content.sharedpreferences; import android.location.address; import android.location.geocoder; import android.location.location; import android.location.locationlistener; import android.location.locationmanager; import android.os.bundle; import android.util.log; import android.view.menu; import android.view.view; import android.view.view.onclicklistener; import android.view.animation.scaleanimation; import android.widget.button; import android.widget.imageview; import android.widget.relativelayout; import android.widget.textview; public class gps extends activity { textview tvlat; textview tvlong; textview tvloc; button weather; long prefsrefreshperiod = (long) 900000.0; sharedpreferences sp; sharedpreferences.editor sd; string city = "new delhi, india"; locationmanager lm; locationlistener listener; relativelayout settinglayout; context _context; @override protected void oncreate(bundle savedinstancestate) { // todo auto-generated method stub super.oncreate(savedinstancestate); setcontentview(r.layout.gps); _context = this; tvlat = (textview) findviewbyid(r.id.tvlat); tvlong = (textview) findviewbyid(r.id.tvlong); tvloc = (textview) findviewbyid(r.id.tvloc); sp = this.getsharedpreferences("gps", 0); sd = sp.edit(); weather = (button) findviewbyid(r.id.getweatherfromgps); weather.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { intent = new intent(gps.this, weather.class); i.putextra("city", city); startactivity(i); } }); getprefsgps(); settinglayout = (relativelayout) findviewbyid(r.id.settinglayout); lm = (locationmanager) getsystemservice(context.location_service); listener = new mylocationlistener(); if (lm.isproviderenabled(locationmanager.gps_provider)) { lm.requestlocationupdates(locationmanager.gps_provider, 0, 0, listener); } else if (lm.isproviderenabled(locationmanager.network_provider)) { lm.requestlocationupdates(locationmanager.network_provider, 0, 0, listener); } else { tvloc.settext("not getting anything!"); } } public string convertpointtolocation(double pointlat, double pointlog) { string address = ""; string locality = ""; geocoder geocoder = new geocoder(this, locale.getdefault()); if (geocoder.ispresent()) { try { list<address> addresses = geocoder.getfromlocation(pointlat, pointlog, 1); if (addresses.size() > 0) { (int index = 0; index < addresses.get(0) .getmaxaddresslineindex(); index++) address += addresses.get(0).getaddressline(index) + " "; } locality = addresses.get(0).getlocality() + "," + addresses.get(0).getcountryname(); } catch (ioexception e) { e.printstacktrace(); } } else { address = "geocoder not available!"; } return locality; } public string reversegeocoding(double lat, double lon) { string address = ""; getreversegeocoding coder = new getreversegeocoding(lat, lon); address = coder.getaddress1() + " " + coder.getaddress2() + " " + coder.getcity() + " " + coder.getcountry(); return address; } class mylocationlistener implements locationlistener { @suppresswarnings("unused") @override public void onlocationchanged(location arg0) { if (arg0 != null) { double lat = arg0.getlatitude(); double longi = arg0.getlongitude(); tvlat.settext(double.tostring(lat)); tvlong.settext(double.tostring(longi)); string loc1 = reversegeocoding(lat, longi); string loc2 = convertpointtolocation(lat, longi); city = (loc1.length() > loc2.length()) ? loc1 : loc2; saveprefsgps(lat, longi, city); if (loc1 != null && loc1 != "" && loc2 != null && loc2 != "") tvloc.settext("http = " + loc1 + "\ngeocoder = " + loc2); else tvloc.settext("its null"); } lm.removeupdates(listener); } @override public void onproviderdisabled(string arg0) { // todo auto-generated method stub tvloc.settext("please enable network!"); } @override public void onproviderenabled(string arg0) { // todo auto-generated method stub tvloc.settext("searching location!"); } @override public void onstatuschanged(string arg0, int arg1, bundle arg2) { // todo auto-generated method stub tvloc.settext("status changed!"); } } @override public boolean oncreateoptionsmenu(menu menu) { // todo auto-generated method stub imageview settings = (imageview) findviewbyid(r.id.ivset); settings.setonclicklistener(new onclicklistener() { @override public void onclick(view arg0) { // todo auto-generated method stub string user = "admin"; string pass = ""; intent intent = new intent(gps.this, second.class); intent.putextra("username", user); intent.putextra("password", pass); startactivity(intent); } }); return super.oncreateoptionsmenu(menu); } @override public boolean onprepareoptionsmenu(menu menu) { // todo auto-generated method stub if (settinglayout.getvisibility() == relativelayout.invisible) { settinglayout.setvisibility(relativelayout.visible); scaleanimation scale = new scaleanimation((float) 1.0, (float) 1.0, (float) 1.0, (float) 1.0); scale.setfillbefore(true); scale.setduration(500); settinglayout.startanimation(scale); return super.onprepareoptionsmenu(menu); } else return false; } @override public void onbackpressed() { // todo auto-generated method stub if (settinglayout.getvisibility() == relativelayout.visible) { settinglayout.setvisibility(relativelayout.invisible); scaleanimation scale = new scaleanimation((float) 0.0, (float) 0.0, (float) 0.0, (float) 0.0); scale.setfillbefore(false); scale.setduration(500); settinglayout.startanimation(scale); } else { super.onbackpressed(); } } public void saveprefsgps(double latitude, double longitude, string city) { savedata sd = new savedata(_context, "gps"); sd.savedoubleprefs("latitude", latitude); sd.savedoubleprefs("longitude", longitude); sd.savestringprefs("city", city); sd.savelongprefs("time", system.currenttimemillis()); sd.savelongprefs("refreshperiod", prefsrefreshperiod); } public void getprefsgps() { double lat = double.longbitstodouble(sp.getlong("latitude", (long) null)); double lon = double.longbitstodouble(sp.getlong("longitude", (long) null)); long period = sp.getlong("refreshperiod", (long) null); long time = sp.getlong("time",(long) null); string city1 = sp.getstring("city", "new delhi,in"); log.e("banana", "data retrieved!"); long currenttime = system.currenttimemillis(); if ((currenttime - time) < period) { tvlat.settext("" + lat); tvlong.settext("" + lon); tvloc.settext("last location : " + city1); city = city1; } } }
the logcat logs are
06-27 11:14:17.938: i/activitymanager(290): start u0 {cmp=com.ritesh.weatherme/.gps} pid 784 06-27 11:14:17.938: w/windowmanager(290): failure taking screenshot (164x273) layer 21010 06-27 11:14:18.088: i/choreographer(784): skipped 33 frames! application may doing work on main thread. 06-27 11:14:18.578: d/dalvikvm(784): gc_concurrent freed 165k, 11% free 2698k/3008k, paused 74ms+20ms, total 251ms 06-27 11:14:18.578: d/dalvikvm(784): wait_for_concurrent_gc blocked 18ms 06-27 11:14:18.828: d/androidruntime(784): shutting down vm 06-27 11:14:18.828: w/dalvikvm(784): threadid=1: thread exiting uncaught exception (group=0x40a71930) 06-27 11:14:18.842: e/androidruntime(784): fatal exception: main 06-27 11:14:18.842: e/androidruntime(784): java.lang.runtimeexception: unable start activity componentinfo{com.ritesh.weatherme/com.ritesh.weatherme.gps}: java.lang.nullpointerexception 06-27 11:14:18.842: e/androidruntime(784): @ android.app.activitythread.performlaunchactivity(activitythread.java:2180) 06-27 11:14:18.842: e/androidruntime(784): @ android.app.activitythread.handlelaunchactivity(activitythread.java:2230) 06-27 11:14:18.842: e/androidruntime(784): @ android.app.activitythread.access$600(activitythread.java:141) 06-27 11:14:18.842: e/androidruntime(784): @ android.app.activitythread$h.handlemessage(activitythread.java:1234) 06-27 11:14:18.842: e/androidruntime(784): @ android.os.handler.dispatchmessage(handler.java:99) 06-27 11:14:18.842: e/androidruntime(784): @ android.os.looper.loop(looper.java:137) 06-27 11:14:18.842: e/androidruntime(784): @ android.app.activitythread.main(activitythread.java:5041) 06-27 11:14:18.842: e/androidruntime(784): @ java.lang.reflect.method.invokenative(native method) 06-27 11:14:18.842: e/androidruntime(784): @ java.lang.reflect.method.invoke(method.java:511) 06-27 11:14:18.842: e/androidruntime(784): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:793) 06-27 11:14:18.842: e/androidruntime(784): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:560) 06-27 11:14:18.842: e/androidruntime(784): @ dalvik.system.nativestart.main(native method) 06-27 11:14:18.842: e/androidruntime(784): caused by: java.lang.nullpointerexception 06-27 11:14:18.842: e/androidruntime(784): @ com.ritesh.weatherme.gps.getprefsgps(gps.java:251) 06-27 11:14:18.842: e/androidruntime(784): @ com.ritesh.weatherme.gps.oncreate(gps.java:72) 06-27 11:14:18.842: e/androidruntime(784): @ android.app.activity.performcreate(activity.java:5104) 06-27 11:14:18.842: e/androidruntime(784): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1080) 06-27 11:14:18.842: e/androidruntime(784): @ android.app.activitythread.performlaunchactivity(activitythread.java:2144) 06-27 11:14:18.842: e/androidruntime(784): ... 11 more 06-27 11:14:18.888: w/activitymanager(290): force finishing activity com.ritesh.weatherme/.gps 06-27 11:14:18.918: w/activitymanager(290): force finishing activity com.ritesh.weatherme/.second 06-27 11:14:19.368: d/dalvikvm(290): gc_for_alloc freed 185k, 19% free 5460k/6712k, paused 164ms, total 168ms 06-27 11:14:19.368: i/dalvikvm-heap(290): grow heap (frag case) 5.743mb 281896-byte allocation 06-27 11:14:19.538: d/dalvikvm(290): gc_for_alloc freed 6k, 19% free 5728k/6988k, paused 165ms, total 165ms 06-27 11:14:19.538: i/choreographer(290): skipped 43 frames! application may doing work on main thread. 06-27 11:14:19.817: w/activitymanager(290): activity pause timeout activityrecord{40e9f0e0 u0 com.ritesh.weatherme/.gps} 06-27 11:14:20.047: i/choreographer(412): skipped 36 frames! application may doing work on main thread. 06-27 11:14:20.077: i/choreographer(290): skipped 45 frames! application may doing work on main thread. 06-27 11:14:20.128: e/surfaceflinger(37): ro.sf.lcd_density must defined build property 06-27 11:14:20.267: e/surfaceflinger(37): ro.sf.lcd_density must defined build property 06-27 11:14:20.527: i/armassembler(37): generated scanline__00000077:03515104_00008001_00000000 [113 ipp] (134 ins) @ [0x4098a6c0:0x4098a8d8] in 2072849 ns 06-27 11:14:20.857: i/choreographer(290): skipped 57 frames! application may doing work on main thread. 06-27 11:14:31.284: w/activitymanager(290): activity destroy timeout activityrecord{40ecc818 u0 com.ritesh.weatherme/.second} 06-27 11:14:31.288: w/activitymanager(290): activity destroy timeout activityrecord{40e9f0e0 u0 com.ritesh.weatherme/.gps} 06-27 11:14:32.398: d/exchangeservice(611): received deviceid email app: null 06-27 11:14:32.398: d/exchangeservice(611): !!! deviceid unknown; stopping self , retrying 06-27 11:14:37.488: d/exchangeservice(611): !!! eas exchangeservice, onstartcommand, startingup = false, running = false 06-27 11:14:37.497: w/activitymanager(290): unable start service intent { act=com.android.email.account_intent } u=0: not found 06-27 11:14:37.497: d/exchangeservice(611): !!! email application not found; stopping self 06-27 11:14:37.517: w/activitymanager(290): unable start service intent { act=com.android.email.account_intent } u=0: not found 06-27 11:14:37.548: e/activitythread(611): service com.android.exchange.exchangeservice has leaked serviceconnection com.android.emailcommon.service.serviceproxy$proxyconnection@40d2d000 bound here 06-27 11:14:37.548: e/activitythread(611): android.app.serviceconnectionleaked: service com.android.exchange.exchangeservice has leaked serviceconnection com.android.emailcommon.service.serviceproxy$proxyconnection@40d2d000 bound here 06-27 11:14:37.548: e/activitythread(611): @ android.app.loadedapk$servicedispatcher.<init>(loadedapk.java:969) 06-27 11:14:37.548: e/activitythread(611): @ android.app.loadedapk.getservicedispatcher(loadedapk.java:863) 06-27 11:14:37.548: e/activitythread(611): @ android.app.contextimpl.bindservice(contextimpl.java:1418) 06-27 11:14:37.548: e/activitythread(611): @ android.app.contextimpl.bindservice(contextimpl.java:1407) 06-27 11:14:37.548: e/activitythread(611): @ android.content.contextwrapper.bindservice(contextwrapper.java:473) 06-27 11:14:37.548: e/activitythread(611): @ com.android.emailcommon.service.serviceproxy.settask(serviceproxy.java:157) 06-27 11:14:37.548: e/activitythread(611): @ com.android.emailcommon.service.serviceproxy.settask(serviceproxy.java:145) 06-27 11:14:37.548: e/activitythread(611): @ com.android.emailcommon.service.accountserviceproxy.getdeviceid(accountserviceproxy.java:116) 06-27 11:14:37.548: e/activitythread(611): @ com.android.exchange.exchangeservice.getdeviceid(exchangeservice.java:1249) 06-27 11:14:37.548: e/activitythread(611): @ com.android.exchange.exchangeservice$7.run(exchangeservice.java:1856) 06-27 11:14:37.548: e/activitythread(611): @ com.android.emailcommon.utility.utility$2.doinbackground(utility.java:551) 06-27 11:14:37.548: e/activitythread(611): @ com.android.emailcommon.utility.utility$2.doinbackground(utility.java:549) 06-27 11:14:37.548: e/activitythread(611): @ android.os.asynctask$2.call(asynctask.java:287) 06-27 11:14:37.548: e/activitythread(611): @ java.util.concurrent.futuretask.run(futuretask.java:234) 06-27 11:14:37.548: e/activitythread(611): @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1080) 06-27 11:14:37.548: e/activitythread(611): @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:573) 06-27 11:14:37.548: e/activitythread(611): @ java.lang.thread.run(thread.java:856) 06-27 11:14:37.698: e/strictmode(611): null 06-27 11:14:37.698: e/strictmode(611): android.app.serviceconnectionleaked: service com.android.exchange.exchangeservice has leaked serviceconnection com.android.emailcommon.service.serviceproxy$proxyconnection@40d2d000 bound here 06-27 11:14:37.698: e/strictmode(611): @ android.app.loadedapk$servicedispatcher.<init>(loadedapk.java:969) 06-27 11:14:37.698: e/strictmode(611): @ android.app.loadedapk.getservicedispatcher(loadedapk.java:863) 06-27 11:14:37.698: e/strictmode(611): @ android.app.contextimpl.bindservice(contextimpl.java:1418) 06-27 11:14:37.698: e/strictmode(611): @ android.app.contextimpl.bindservice(contextimpl.java:1407) 06-27 11:14:37.698: e/strictmode(611): @ android.content.contextwrapper.bindservice(contextwrapper.java:473) 06-27 11:14:37.698: e/strictmode(611): @ com.android.emailcommon.service.serviceproxy.settask(serviceproxy.java:157) 06-27 11:14:37.698: e/strictmode(611): @ com.android.emailcommon.service.serviceproxy.settask(serviceproxy.java:145) 06-27 11:14:37.698: e/strictmode(611): @ com.android.emailcommon.service.accountserviceproxy.getdeviceid(accountserviceproxy.java:116) 06-27 11:14:37.698: e/strictmode(611): @ com.android.exchange.exchangeservice.getdeviceid(exchangeservice.java:1249) 06-27 11:14:37.698: e/strictmode(611): @ com.android.exchange.exchangeservice$7.run(exchangeservice.java:1856) 06-27 11:14:37.698: e/strictmode(611): @ com.android.emailcommon.utility.utility$2.doinbackground(utility.java:551) 06-27 11:14:37.698: e/strictmode(611): @ com.android.emailcommon.utility.utility$2.doinbackground(utility.java:549) 06-27 11:14:37.698: e/strictmode(611): @ android.os.asynctask$2.call(asynctask.java:287) 06-27 11:14:37.698: e/strictmode(611): @ java.util.concurrent.futuretask.run(futuretask.java:234) 06-27 11:14:37.698: e/strictmode(611): @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1080) 06-27 11:14:37.698: e/strictmode(611): @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:573) 06-27 11:14:37.698: e/strictmode(611): @ java.lang.thread.run(thread.java:856) 06-27 11:14:37.698: w/activitymanager(290): unbind failed: not find connection android.os.binderproxy@40d932f8 06-27 11:14:37.727: e/activitythread(611): service com.android.exchange.exchangeservice has leaked serviceconnection com.android.emailcommon.service.serviceproxy$proxyconnection@40d2cc38 bound here 06-27 11:14:37.727: e/activitythread(611): android.app.serviceconnectionleaked: service com.android.exchange.exchangeservice has leaked serviceconnection com.android.emailcommon.service.serviceproxy$proxyconnection@40d2cc38 bound here 06-27 11:14:37.727: e/activitythread(611): @ android.app.loadedapk$servicedispatcher.<init>(loadedapk.java:969) 06-27 11:14:37.727: e/activitythread(611): @ android.app.loadedapk.getservicedispatcher(loadedapk.java:863) 06-27 11:14:37.727: e/activitythread(611): @ android.app.contextimpl.bindservice(contextimpl.java:1418) 06-27 11:14:37.727: e/activitythread(611): @ android.app.contextimpl.bindservice(contextimpl.java:1407) 06-27 11:14:37.727: e/activitythread(611): @ android.content.contextwrapper.bindservice(contextwrapper.java:473) 06-27 11:14:37.727: e/activitythread(611): @ com.android.emailcommon.service.serviceproxy.settask(serviceproxy.java:157) 06-27 11:14:37.727: e/activitythread(611): @ com.android.emailcommon.service.serviceproxy.settask(serviceproxy.java:145) 06-27 11:14:37.727: e/activitythread(611): @ com.android.emailcommon.service.serviceproxy.test(serviceproxy.java:191) 06-27 11:14:37.727: e/activitythread(611): @ com.android.exchange.exchangeservice$7.run(exchangeservice.java:1850) 06-27 11:14:37.727: e/activitythread(611): @ com.android.emailcommon.utility.utility$2.doinbackground(utility.java:551) 06-27 11:14:37.727: e/activitythread(611): @ com.android.emailcommon.utility.utility$2.doinbackground(utility.java:549) 06-27 11:14:37.727: e/activitythread(611): @ android.os.asynctask$2.call(asynctask.java:287) 06-27 11:14:37.727: e/activitythread(611): @ java.util.concurrent.futuretask.run(futuretask.java:234) 06-27 11:14:37.727: e/activitythread(611): @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1080) 06-27 11:14:37.727: e/activitythread(611): @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:573) 06-27 11:14:37.727: e/activitythread(611): @ java.lang.thread.run(thread.java:856) 06-27 11:14:37.827: e/strictmode(611): null 06-27 11:14:37.827: e/strictmode(611): android.app.serviceconnectionleaked: service com.android.exchange.exchangeservice has leaked serviceconnection com.android.emailcommon.service.serviceproxy$proxyconnection@40d2cc38 bound here 06-27 11:14:37.827: e/strictmode(611): @ android.app.loadedapk$servicedispatcher.<init>(loadedapk.java:969) 06-27 11:14:37.827: e/strictmode(611): @ android.app.loadedapk.getservicedispatcher(loadedapk.java:863) 06-27 11:14:37.827: e/strictmode(611): @ android.app.contextimpl.bindservice(contextimpl.java:1418) 06-27 11:14:37.827: e/strictmode(611): @ android.app.contextimpl.bindservice(contextimpl.java:1407) 06-27 11:14:37.827: e/strictmode(611): @ android.content.contextwrapper.bindservice(contextwrapper.java:473) 06-27 11:14:37.827: e/strictmode(611): @ com.android.emailcommon.service.serviceproxy.settask(serviceproxy.java:157) 06-27 11:14:37.827: e/strictmode(611): @ com.android.emailcommon.service.serviceproxy.settask(serviceproxy.java:145) 06-27 11:14:37.827: e/strictmode(611): @ com.android.emailcommon.service.serviceproxy.test(serviceproxy.java:191) 06-27 11:14:37.827: e/strictmode(611): @ com.android.exchange.exchangeservice$7.run(exchangeservice.java:1850) 06-27 11:14:37.827: e/strictmode(611): @ com.android.emailcommon.utility.utility$2.doinbackground(utility.java:551) 06-27 11:14:37.827: e/strictmode(611): @ com.android.emailcommon.utility.utility$2.doinbackground(utility.java:549) 06-27 11:14:37.827: e/strictmode(611): @ android.os.asynctask$2.call(asynctask.java:287) 06-27 11:14:37.827: e/strictmode(611): @ java.util.concurrent.futuretask.run(futuretask.java:234) 06-27 11:14:37.827: e/strictmode(611): @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1080) 06-27 11:14:37.827: e/strictmode(611): @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:573) 06-27 11:14:37.827: e/strictmode(611): @ java.lang.thread.run(thread.java:856) 06-27 11:14:37.847: d/dalvikvm(611): gc_concurrent freed 384k, 18% free 2477k/3004k, paused 72ms+80ms, total 275ms 06-27 11:14:37.847: w/activitymanager(290): unbind failed: not find connection android.os.binderproxy@40f56dd0'
Comments
Post a Comment