Corresponding method handler not found - Android XML

I had made a mistake in declaring the context in the XML. I had used .activities.YearViewActivity but the changeMonth method was declared in a different activity, which was causing the error.

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".activities.MonthViewActivity"> // Changed here

    <ImageView
        android:id="@+id/month_view_prev_month"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_keyboard_arrow_left_black_24dp"
        android:onClick="changeMonth"/>

</android.support.design.widget.CoordinatorLayout>

Changing the tools:context to the class of the calling activity fixed the error for me.


You can try this to solve the issue

XML in .MainActivity

 <TextView
    android:id="@+id/numbers"
    style="@style/CategoryStyle"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/category_numbers"
    android:text="@string/category_numbers"
    android:onClick="openNumberList"/>

Java Code

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void openNumberList(View view) {
        Intent i = new Intent(this, NumberActivity.class);
        startActivity(i);
    }
}

declare a method in MainActivity with the name of openNumberList. You don't need to define it in NumberActitvity