How to Solve Error: Could Not Find Method Onclick(View) in a Parent or Ancestor Context for Android:Onclick

How do I solve Could not find method in a parent or ancestor Context for android:onClick attribute?

android:onClick="startService" will not called in fragment. You should use OnClickListener instead to handle this type of events.

Another approach is declare the startService function in activity, then call the fragment method from the activity.

Kindly refer Android app crashing (fragment and xml onclick) to know more.

How to solve error: Could not find method onClick(View) in a parent or ancestor Context for android:onClick

I had the same problem and in my case, I changed Button in XML to android.support.v7.widget.AppCompatButton and it worked.

Code with Error:

 <Button
.... />

Fixed Code:

 <android.support.v7.widget.AppCompatButton
.... />

Could not find method in a parent or ancestor Context for android:onClick attribute

You must have "openHelp1" method in same activity class where you use xlm file with attribute android:onClick="openHelp1"

You can't call method from another activity in this way.

Could not find method value(View) in a parent or ancestor Context for android:onClick

Just remove android:onClick="value" and also android:onClick="button" from your layout



Related Topics



Leave a reply



Submit