sqlite - Android input dialog -


i have class showing custom dialog

public class add_category_dialog { public  string inputed_value; private context context; public add_category_dialog(context context){     this.context=context; } public void showdialog(){         alertdialog.builder alert = new alertdialog.builder(context);           alert.settitle("title");          alert.setmessage("message");            final edittext input = new edittext(context);          alert.setview(input);           alert.setpositivebutton("ok", new dialoginterface.onclicklistener() {          public void onclick(dialoginterface dialog, int whichbutton) {          inputed_value = input.gettext().tostring();             }          });           alert.setnegativebutton("cancel", new dialoginterface.onclicklistener() {          public void onclick(dialoginterface dialog, int whichbutton) {               return;          }         });          alert.show();   } 

}

calling main activity:

 @override public boolean onoptionsitemselected(menuitem item){     switch(item.getitemid()){     case r.id.add_category_item:         add_category_dialog add_dialog=new add_category_dialog(getbasecontext());         add_dialog.showdialog();         addcategory(add_dialog.inputed_value);         return true;     }     return false; } 

when running in emulator runtime error occures, logcat:

android.view.windowmanager$badtokenexception: unable add window -- token null not application

upd have sqlite error code 19, constraint failed

 private void addcategory(string string){     sqlitedatabase db=recipes.getwritabledatabase();     contentvalues values=new contentvalues();     values.put(category_name, string);     db.insertorthrow(category_table, null, values); } 

try replacing getbasecontext() this.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -