title: How can I access a setter method of MainActivity class, from a fragment classe?
body: <p>This is the setter method in MainActivity class</p>
  
  <pre><code>public void setNumPlats(int numero){
  this.numPlats = numero;
  }
  </code></pre>
  
  <p>I'm trying to acces to this method from fragment class, but i dont know how i need to do this.</p>
  
  <p>In the fragment class i'm trying to do this</p>
  
  <pre><code>I'm trying it, and it doesnt makes error when i put it into onAttach, but when i execute the app it crashes. @Override
  public void onAttach(Activity activity) {
      super.onAttach(activity);
  
  }
  
  ((MainActivity)getActivity()).setNumPlats(adapter.getNumPlats());
  @Override
  public void onDetach() {
      super.onDetach();
  }
  </code></pre>