nullpointerexception - Android Application finish prob -
i using custom alert dialog. if user go negative button of code need close app totally. using following code.
public class testapp extends tabactivity { private int tabid = 0; /** called when activity first created. */ @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); final tabhost tabhost = gettabhost(); // activity tabhost tabhost.tabspec spec; // resusable tabspec each tab intent intent; // reusable intent each tab intent myint = this.getintent(); tabid = myint.getintextra("tab_id", 0); ....................... ......................... ....................... tabhost.setcurrenttab(tabid); showreward(this); } private void showreward(context c) { // todo auto-generated method stub final alertdialog.builder builder; alertdialog alertdialog; context mcontext = c; layoutinflater inflater = (layoutinflater) mcontext.getsystemservice(layout_inflater_service); view layout = inflater.inflate(r.layout.custom_dialog, (viewgroup) findviewbyid(r.id.layout_root)); textview text = (textview) layout.findviewbyid(r.id.title); text.settext("sample text"); text.setgravity(gravity.center); textview msg = (textview) layout.findviewbyid(r.id.msg); msg.settext("sample text."); builder = new alertdialog.builder(mcontext); builder.setview(layout); builder.setpositivebutton("ok", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int which) { dialog.cancel(); } }); builder.setnegativebutton("cancel", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int which) { log.d(null,"step1"); dialog.cancel(); log.d(null,"step2"); closeapp(); } }); alertdialog = builder.create(); alertdialog.show(); } private void closeapp(){ log.d(null,"step3"); this.finish(); } }
but working before add showreward() function. when u add function, dialog box appearing perfectly. if click on negative button giving nullpointerexception due "unable destroy activity". whats problem code?
this problem related cursor.close() @ time finish. no such close during finish()
Comments
Post a Comment