java - How to perform a method of another class when I click the Accept Button of my Dialog which is located in another class? -


this snippet here in mainactivity.java calls "newdrawing()" method of class named tools.java.

public void onclick(view v) {     string color = null;      switch (v.getid()){          case r.id.newdraw_a:             tools buttons = new tools(this);             buttons.newdrawing();             break; 

the "newdrawing()" method dialog asks user add drawing or cancel. when user clicks "accept", want call method class named "canvas_class.java".

    public class tools extends view{      public canvas_class drawing;      public tools(context context) {             super(context);         }      public void newdrawing(){         final alertdialog.builder newdialog = new alertdialog.builder(this.getcontext());         newdialog.settitle("new drawing?");         newdialog.setmessage("you overwrite current drawings. sure want add drawing?");         newdialog.setpositivebutton("accept", new dialoginterface.onclicklistener(){             public void onclick(dialoginterface dialog, int which){                 dialog.dismiss();                 drawing.newdrawing();             }         });         newdialog.setnegativebutton("cancel", new dialoginterface.onclicklistener() {             public void onclick(dialoginterface dialog, int which) {                 dialog.cancel();             }         });         newdialog.show();      }  } 

now, want ask wrong code in tools.java force closes when click accept. thank you.

my canvas_class looks this

public class canvas_class extends view {  private canvas drawcanvas;  public canvas_class(context context, attributeset attrs) {     super(context, attrs);     setupdrawing(); }  public void newdrawing(){     drawcanvas.drawcolor(0, porterduff.mode.clear);     invalidate();  } 

you getting nullpointerexception as

drawing null throws exception, please initialize

canvas_class drawing variable doesnt throw exception


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -