0

I have three files such as

  1. activity class
  2. db handler class
  3. fragment class

From my resource file, on a button click I am calling a method (add). The method is defined in the DB Class. and I am trying to call it from the fragment class related with the res file. But when I do I am getting an error:

Could not find a method add(View) in the activity class MainActivity for onClick handler on view class android.widget.Button with id 'btStartCall'

I think I need to initialize the method in activity class to use it. But I am not sure how to do it. Can anyone help me with a simple example?

halfer
  • 19,824
  • 17
  • 99
  • 186
Jobin
  • 91
  • 12
  • You should add `add(View)` method on your `MainActivity` class. – M D Mar 11 '15 at 05:48
  • It would help if you could supply some [sample code](http://stackoverflow.com/help/mcve). – Amos M. Carpenter Mar 11 '15 at 05:55
  • I defined the method in the db class and called that method by passing parameters from fragment class file. public void add(View v){ //do your job } The same I did in the fragment class. will it be fine if i copy the same method and the method body to the main activity class? – Jobin Mar 11 '15 at 07:27

1 Answers1

1

But when i do I am getting an error telling "Could not find a method add(View) in the activity class MainActivity for onClick handler on view class android.widget.Button with id 'btStartCall'"

You should add add(View) method in your MainActivity just like:

  public void add(View v){
  //do your job
  }
M D
  • 47,665
  • 9
  • 93
  • 114