android - Can anyone suggest me what this below logcat is saying? -
04-18 10:43:01.765: i/system.out(23278): manual hours === 9:8 04-18 10:43:01.820: i/system.out(23278): ---gpsonoff.detectgps() 04-18 10:43:01.835: d/androidruntime(23278): shutting down vm 04-18 10:43:01.835: w/dalvikvm(23278): threadid=1: thread exiting uncaught exception (group=0x40018578) 04-18 10:43:01.851: e/androidruntime(23278): fatal exception: main 04-18 10:43:01.851: e/androidruntime(23278): java.lang.runtimeexception: unable start activity componentinfo{com.example.security/com.example.security.colect_data_from_usr_activity}: android.view.windowmanager$badtokenexception: unable add window -- token android.app.localactivitymanager$localactivityrecord@40538820 not valid; activity running? 04-18 10:43:01.851: e/androidruntime(23278): @ android.app.activitythread.performlaunchactivity(activitythread.java:1651) 04-18 10:43:01.851: e/androidruntime(23278): @ android.app.activitythread.startactivitynow(activitythread.java:1491) 04-18 10:43:01.851: e/androidruntime(23278): @ android.app.localactivitymanager.movetostate(localactivitymanager.java:127) 04-18 10:43:01.851: e/androidruntime(23278): @ android.app.localactivitymanager.startactivity(localactivitymanager.java:339) 04-18 10:43:01.851: e/androidruntime(23278): @ com.example.security.startinspection$3.onclick(startinspection.java:72) 04-18 10:43:01.851: e/androidruntime(23278): @ android.view.view.performclick(view.java:2485) 04-18 10:43:01.851: e/androidruntime(23278): @ android.view.view$performclick.run(view.java:9080) 04-18 10:43:01.851: e/androidruntime(23278): @ android.os.handler.handlecallback(handler.java:587) 04-18 10:43:01.851: e/androidruntime(23278): @ android.os.handler.dispatchmessage(handler.java:92) 04-18 10:43:01.851: e/androidruntime(23278): @ android.os.looper.loop(looper.java:130) 04-18 10:43:01.851: e/androidruntime(23278): @ android.app.activitythread.main(activitythread.java:3687) 04-18 10:43:01.851: e/androidruntime(23278): @ java.lang.reflect.method.invokenative(native method) 04-18 10:43:01.851: e/androidruntime(23278): @ java.lang.reflect.method.invoke(method.java:507) 04-18 10:43:01.851: e/androidruntime(23278): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:867) 04-18 10:43:01.851: e/androidruntime(23278): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:625) 04-18 10:43:01.851: e/androidruntime(23278): @ dalvik.system.nativestart.main(native method) 04-18 10:43:01.851: e/androidruntime(23278): caused by: android.view.windowmanager$badtokenexception: unable add window -- token android.app.localactivitymanager$localactivityrecord@40538820 not valid; activity running? 04-18 10:43:01.851: e/androidruntime(23278): @ android.view.viewroot.setview(viewroot.java:532) 04-18 10:43:01.851: e/androidruntime(23278): @ android.view.windowmanagerimpl.addview(windowmanagerimpl.java:177) 04-18 10:43:01.851: e/androidruntime(23278): @ android.view.windowmanagerimpl.addview(windowmanagerimpl.java:91) 04-18 10:43:01.851: e/androidruntime(23278): @ android.view.window$localwindowmanager.addview(window.java:424) 04-18 10:43:01.851: e/androidruntime(23278): @ android.app.dialog.show(dialog.java:241) 04-18 10:43:01.851: e/androidruntime(23278): @ com.example.security.colect_data_from_usr_activity.showgpsondialog(colect_data_from_usr_activity.java:195) 04-18 10:43:01.851: e/androidruntime(23278): @ com.example.security.colect_data_from_usr_activity.detectgps(colect_data_from_usr_activity.java:172) 04-18 10:43:01.851: e/androidruntime(23278): @ com.example.security.colect_data_from_usr_activity.oncreate(colect_data_from_usr_activity.java:95) 04-18 10:43:01.851: e/androidruntime(23278): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1047) 04-18 10:43:01.851: e/androidruntime(23278): @ android.app.activitythread.performlaunchactivity(activitythread.java:1615) 04-18 10:43:01.851: e/androidruntime(23278): ... 15 more
colect_data_from_usr_activity.java
public class colect_data_from_usr_activity extends activity { dialog dialog; button cnf_exit,cnf_cancel; private checkbox chk1, chk2,chk3,chk4,chk5; button btn_sbmt; string address=""; string adr1,adr2; private int myear; private int mmonth; private int mday; private textview edt_date,edt_time,txt_location,edt_note,txt_buildingname; private int mhour,mminute,msecond; static final int time_dialog_id = 1; static final int date_dialog_id = 0; locationmanager loc_mgr ; mylocationlistener location_listener; @override protected void oncreate(bundle savedinstancestate) { // todo auto-generated method stub super.oncreate(savedinstancestate); requestwindowfeature(window.feature_no_title); setcontentview(r.layout.collect_data_frm_user_layout); dialog = new dialog(actgroup.group); dialog.setcontentview(r.layout.confirmexit); dialog.settitle(html.fromhtml("<font color='white'>exit</font>")); dialog.show(); cnf_exit=(button) dialog.findviewbyid(r.id.cnf_exit); cnf_cancel =(button) dialog.findviewbyid(r.id.cnf_cancel); cnf_exit.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { finish(); } }); cnf_cancel.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub dialog.cancel(); } }); simpledateformat date_format = new simpledateformat("dd-mmm-yy"); simpledateformat time_format = new simpledateformat("hh:mm:ss a"); date date = new date(); getwindow().setsoftinputmode( windowmanager.layoutparams.soft_input_state_always_hidden); loc_mgr = (locationmanager) getsystemservice(context.location_service); detectgps(); /* bundle bundle = getintent().getextras(); string strloc = bundle.getstring("lctn"); system.out.println("======>>>>" + strloc); */ addlisteneronchkios(); addlisteneronbutton(); txt_location = (textview)findviewbyid(r.id.txt_location); txt_location.settext(address); txt_buildingname = (textview)findviewbyid(r.id.textview_building_name); txt_buildingname.settext(tracker.building_name); edt_note = (textview) findviewbyid(r.id.edittext_note); edt_date = (textview) findviewbyid(r.id.txtvw_date); date d = new date(); java.text.dateformat df = android.text.format.dateformat.getdateformat(getapplicationcontext()); calendar calendar = calendar.getinstance(); calendar.settime(new date()); edt_date.settext(date_format.format(date)); edt_time=(textview) findviewbyid(r.id.edittext_time); edt_time.settext(time_format.format(date)); edt_date.setonclicklistener(new view.onclicklistener() { public void onclick(view v) { showdialog(date_dialog_id); } }); final calendar c = calendar.getinstance(); myear = c.get(calendar.year); mmonth = c.get(calendar.month); mday = c.get(calendar.day_of_month); mhour = c.get(calendar.hour); mminute = c.get(calendar.minute); msecond = c.get(calendar.second); } private void updatedate() { edt_date.settext(new stringbuilder() .append(mday).append("/") .append(mmonth + 1).append("/") .append(myear).append(" ")); showdialog(date_dialog_id); } //-------------------------------------------update time---------------------// public void updatetime() { edt_time.settext(new stringbuilder() .append(pad(mhour)).append(":") .append(pad(mminute))); } private void detectgps() { // todo auto-generated method stub system.out.println("---gpsonoff.detectgps()"); if(loc_mgr.isproviderenabled(locationmanager.gps_provider)) { trackgps(); } else { showgpsondialog(); } } public void showgpsondialog() { // todo auto-generated method stub alertdialog.builder alertdialogbuilder = new alertdialog.builder(this); alertdialogbuilder.setmessage("gps disabled in device. enable it?") .setcancelable(false) .setpositivebutton("settings", new dialoginterface.onclicklistener(){ public void onclick(dialoginterface dialog, int id){ intent callgpssettingintent = new intent( android.provider.settings.action_location_source_settings); startactivityforresult(callgpssettingintent,55); } }); alertdialogbuilder.setnegativebutton("cancel",new dialoginterface.onclicklistener(){ public void onclick(dialoginterface dialog, int id){ dialog.cancel(); } }); alertdialog alert = alertdialogbuilder.create(); alert.show(); } protected void showlastknownlocation() { location location = loc_mgr.getlastknownlocation(locationmanager.gps_provider); if (location == null) { system.out.println("location gps null"); location = loc_mgr.getlastknownlocation(locationmanager.network_provider); } if(location!=null) { string message = string.format( "last location \n longitude: %1$s \n latitude: %2$s", location.getlongitude(), location.getlatitude() ); system.out.println(message); getaddress(location.getlatitude(),location.getlongitude()); } else { system.out.println("location null"); }} @override protected void onactivityresult(int requestcode, int resultcode, intent data) { // todo auto-generated method stub detectgps(); } public void trackgps() { // todo auto-generated method stub showlastknownlocation(); location_listener = new mylocationlistener(); loc_mgr.requestlocationupdates(locationmanager.gps_provider,0,0,location_listener); } private void getaddress(double latitude,double longitude) { // todo auto-generated method stub try { geocoder geocoder = new geocoder(colect_data_from_usr_activity.this); try { list<address> arr = geocoder.getfromlocation(latitude,longitude,1); if(arr.size() !=0 && arr != null) { (int = 0; < arr.get(0).getmaxaddresslineindex(); i++) { system.out.println("addressss "+arr.get(0).getaddressline(i)); if(i == 0) { adr1 = arr.get(0).getaddressline(i); }else if(i == 1) { adr2 = arr.get(0).getaddressline(i); } address += arr.get(0).getaddressline(i)+"\n"; } } } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); system.out.println("--- getadres exception"); } } catch (exception e) { // todo: handle exception system.out.println(e.tostring()); }} public class mylocationlistener implements locationlistener { public void onlocationchanged(location location) { // todo auto-generated method stub if(location != null) { getaddress(location.getlatitude(), location.getlongitude()); } else { system.out.println("--- location null;"); } } @override public void onproviderdisabled(string provider) { // todo auto-generated method stub system.out.println("gpsonoff.mylocationlistener.onproviderdisabled()"); } @override public void onproviderenabled(string provider) { // todo auto-generated method stub system.out.println("gpsonoff.mylocationlistener.onproviderenabled()"); } @override public void onstatuschanged(string provider, int status, bundle extras) { // todo auto-generated method stub system.out.println("gpsonoff.mylocationlistener.onstatuschanged()"); }} private void checkenablegps(){ string provider = settings.secure.getstring(getcontentresolver(), settings.secure.location_providers_allowed); if(provider.contains("gps")){ //gps enabled system.out.println("provide -- "+provider); // toast.maketext(start_hr_activity.this, "gps enabled: " + provider, // toast.length_long).show(); }else{ //intent intent = new intent(settings.action_security_settings); intent intent = new intent(settings.action_location_source_settings); startactivity(intent); } } private static string pad(int c) { if (c >= 10) return string.valueof(c); else return "0" + string.valueof(c); } //datepicker dialog generation private datepickerdialog.ondatesetlistener mdatesetlistener = new datepickerdialog.ondatesetlistener() { public void ondateset(datepicker view, int year, int monthofyear, int dayofmonth) { myear = year; mmonth = monthofyear; mday = dayofmonth; updatedate(); } }; // timepicker dialog generation private timepickerdialog.ontimesetlistener mtimesetlistener = new timepickerdialog.ontimesetlistener() { public void ontimeset(timepicker view, int hourofday, int minute) { mhour = hourofday; mminute = minute; updatetime(); } }; @override protected dialog oncreatedialog(int id) { switch (id) { case date_dialog_id: return new datepickerdialog(this, mdatesetlistener, myear, mmonth,mday); case time_dialog_id: return new timepickerdialog(this, mtimesetlistener, mhour, mminute, false); } return null; } public void addlisteneronchkios() { chk1 = (checkbox) findviewbyid(r.id.checkbox_windowopen); chk1.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { if (((checkbox) v).ischecked()) { } } }); } public void addlisteneronbutton() { chk1 = (checkbox) findviewbyid(r.id.checkbox_windowopen); chk2 = (checkbox) findviewbyid(r.id.checkbox_dooropen); chk3 = (checkbox) findviewbyid(r.id.checkbox_employeeonsite); chk4 = (checkbox) findviewbyid(r.id.checkbox_glassbroken); chk5 = (checkbox) findviewbyid(r.id.checkbox_doorbroken); btn_sbmt = (button) findviewbyid(r.id.button_sbmt); btn_sbmt.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { string str_1 = string.valueof(chk1); string str_2 = string.valueof(chk2); string str_3 = string.valueof(chk3); string str_4 = string.valueof(chk4); string str_5 = string.valueof(chk5); string str_dt = edt_date.gettext().tostring(); string str_tm = edt_time.gettext().tostring(); system.out.println("********_--------________--- "+ str_tm); string str_loct = txt_location.gettext().tostring(); str_loct.valueof(txt_location.gettext().tostring()); string str_note = edt_note.gettext().tostring(); string incidents=""; if(chk1.ischecked()) { incidents += chk1.gettext().tostring()+"\n"; } if(chk2.ischecked()) { incidents += chk2.gettext().tostring()+"\n"; } if(chk3.ischecked()) { incidents += chk3.gettext().tostring()+"\n"; } if(chk4.ischecked()) { incidents += chk4.gettext().tostring()+"\n"; } if(chk5.ischecked()) { incidents += chk5.gettext().tostring()+"\n"; } bundle b=new bundle(); b.putstring("c1", incidents); b.putstring("date", str_dt); b.putstring("time", str_tm); b.putstring("lctn",str_loct); b.putstring("note", str_note); b.putstring("adr1", adr1); b.putstring("adr2", adr2); loc_mgr.removeupdates(location_listener); intent intnt = new intent(v.getcontext(), colected_data_result_activity.class); intnt.putextras(b); view view = actgroup.group.getlocalactivitymanager().startactivity("colected_data_result_activity", intnt.addflags(intent.flag_activity_clear_top)).getdecorview(); actgroup.group.replaceview(view); // toast.maketext(report.this, result.tostring(),toast.length_long).show(); } }); } @override public void onbackpressed() { // todo auto-generated method stub dialog.show(); } }
latest logcat
04-18 11:49:34.414: d/androidruntime(27731): shutting down vm 04-18 11:49:34.414: w/dalvikvm(27731): threadid=1: thread exiting uncaught exception (group=0x40018578) 04-18 11:49:34.453: e/androidruntime(27731): fatal exception: main 04-18 11:49:34.453: e/androidruntime(27731): java.lang.runtimeexception: unable start activity componentinfo{com.example.security/com.example.security.colect_data_from_usr_activity}: java.lang.nullpointerexception 04-18 11:49:34.453: e/androidruntime(27731): @ android.app.activitythread.performlaunchactivity(activitythread.java:1651) 04-18 11:49:34.453: e/androidruntime(27731): @ android.app.activitythread.startactivitynow(activitythread.java:1491) 04-18 11:49:34.453: e/androidruntime(27731): @ android.app.localactivitymanager.movetostate(localactivitymanager.java:127) 04-18 11:49:34.453: e/androidruntime(27731): @ android.app.localactivitymanager.startactivity(localactivitymanager.java:339) 04-18 11:49:34.453: e/androidruntime(27731): @ com.example.security.startinspection$3.onclick(startinspection.java:72) 04-18 11:49:34.453: e/androidruntime(27731): @ android.view.view.performclick(view.java:2485) 04-18 11:49:34.453: e/androidruntime(27731): @ android.view.view$performclick.run(view.java:9080) 04-18 11:49:34.453: e/androidruntime(27731): @ android.os.handler.handlecallback(handler.java:587) 04-18 11:49:34.453: e/androidruntime(27731): @ android.os.handler.dispatchmessage(handler.java:92) 04-18 11:49:34.453: e/androidruntime(27731): @ android.os.looper.loop(looper.java:130) 04-18 11:49:34.453: e/androidruntime(27731): @ android.app.activitythread.main(activitythread.java:3687) 04-18 11:49:34.453: e/androidruntime(27731): @ java.lang.reflect.method.invokenative(native method) 04-18 11:49:34.453: e/androidruntime(27731): @ java.lang.reflect.method.invoke(method.java:507) 04-18 11:49:34.453: e/androidruntime(27731): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:867) 04-18 11:49:34.453: e/androidruntime(27731): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:625) 04-18 11:49:34.453: e/androidruntime(27731): @ dalvik.system.nativestart.main(native method) 04-18 11:49:34.453: e/androidruntime(27731): caused by: java.lang.nullpointerexception 04-18 11:49:34.453: e/androidruntime(27731): @ com.example.security.colect_data_from_usr_activity.detectgps(colect_data_from_usr_activity.java:159) 04-18 11:49:34.453: e/androidruntime(27731): @ com.example.security.colect_data_from_usr_activity.oncreate(colect_data_from_usr_activity.java:66) 04-18 11:49:34.453: e/androidruntime(27731): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1047) 04-18 11:49:34.453: e/androidruntime(27731): @ android.app.activitythread.performlaunchactivity(activitythread.java:1615) 04-18 11:49:34.453: e/androidruntime(27731): ... 15 more
you can't show dialog within oncreate
; that's what's causing cryptic exception. window has not been created yet. move detectgps
call (and other dialog showing code) onstart
, should work.
in fact, though, should overriding oncreatedialog
, using showdialog
show dialogs. allows activity correctly manage dialogs during activity lifecycle events.
Comments
Post a Comment