I’m trying to create an app for Android, and I follow this tutorial http://developer.android.com/training/basics/firstapp/starting-activity.html
there is a part
/** Called when the user clicks the Send button */
public void sendMessage(View view) {
// Do something in response to button
}
then I followed this tutorial and everything worked, untill I remove parameter View view
my question is just why everytime I remove it, so the function just be:
/** Called when the user clicks the Send button */
public void sendMessage() {
// Do something in response to button
}
and I run the app, it forced close.
could anyone enlighten me? thank you
the method (typically called
onClick(View view)) method takes a parameter (the View it is associated with). see http://developer.android.com/reference/android/view/View.OnClickListener.html for more information on the function. if you leave off the parameter you wouldn’t expect it to work, would you?