Press "Enter" to skip to content

Error “Could not find method in a parent or ancestor Context” how do i fix this?

Last updated on December 24, 2021

i’m trying to send some string from edittext that is located on my first activity into the second activity by pressing Button and i want to see this string in the edittext on that second activity, maybe somebody could help me please

My onClick method:

public void calendarOR(View v, AdapterView<?> parent, int position, long id) {
            String data = cala.getText().toString();
            Intent intent = new Intent(getApplicationContext(), calendar.class);

The second activity:

  Bundle extras = getIntent().getExtras();
    if (extras != null) {
        userId = extras.getLong("id");
    if (userId > 0) {
        userCursor = db.rawQuery("select * from " + dbelper.TABLE + " where " + dbelper.COLUMN_ID + "=?", new String[]{String.valueOf(userId)});

But i get an Error:

        java.lang.IllegalStateException: Could not find method calendarOR(View) in a parent or 
        ancestor Context for android:onClick attribute defined on view class with id 'buttonCal2'