membersound
membersound

Reputation: 86627

onClick does not find its method

When I click a button, its method does not get called, but exception is thrown. Why?

Caused by: java.lang.NoSuchMethodException: myMethod [class android.view.View]

main.xml:

android:onClick="myMethod"

Activity:

public class MyActivity extends Activity {
//onCreate etc

    public void myMethod() {
    }
}

Upvotes: 0

Views: 76

Answers (1)

Samir Mangroliya
Samir Mangroliya

Reputation: 40406

 public void myMethod(View view) {

    }

you forgot parameter View of myMethod

And if you have no view then you can call method myMethod(null)

Upvotes: 5

Related Questions