J Adonai Dagdag
J Adonai Dagdag

Reputation: 1945

Android Studio XML error "Corresponding method handler not found" on onClick

Why do I get error "Corresponding method handler not found" on the XML onClick line, after naming the onClick in XML and calling it on Main Activity?

Snippet from activity_main.xml:

        <Button
            android:id="@+id/buPercentage"
            android:layout_width="30pt"
            android:layout_height="30pt"
            android:layout_weight="1"
            android:background="@color/lightgray"
            android:onClick="buPercentageEvent" //Error says Corresponding method handler not found
            android:text="%"
            android:textSize="18sp" />

Snippet from MainActivity.kt

fun buPercentageEvent()
{
    val convertToDecimal = displayText.text.toString()
    val newNumber = convertToDecimal.toDouble() / 100
    displayText.setText(newNumber.toString())
}

Upvotes: 3

Views: 2143

Answers (1)

Ankit Khare
Ankit Khare

Reputation: 1385

Do this

fun test(view: View){
        Log.e("Click","Yes")
    }

This will work.

Upvotes: 2

Related Questions