Android SDK Tools Rev.17 - onClick - Corresponding method handler not found
Asked Answered
F

3

1

I updated Android SDK Tools to revision 17 and after I opened Eclipse I found a list of new errors in the 'Problems' view which weren't there before the update. These errors were in XML Layout files where I had defined the onClick attribute for buttons. On mouse-over the error message example:

"Corresponding method handler 'public void @string/timespanDefinition_btnSave_Click(android.view.View)' not found"

returned. I have already defined the corresponding method handler and the string representation for this event name. What is the cause and solution of this problem?

Some code:

XML Layout

<ToggleButton
        android:id="@+id/timespanDefinition_tglVibration"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:checked="true"
        android:onClick="@string/timespanDefinition_tglVibration_Click"
        android:saveEnabled="true" />

Activity which inflates XML Layout

public class TimespanDefinitionActivity extends Activity

{

// -- Attributes -- //

private long mRowId = -1;
private StringBuilder mBitWeekDays;
private String mTitle;

private EditText txtTitle;
private TabHost tabHost;
private TimePicker tmepkrStart;
private TimePicker tmepkrEnd;
private CheckBox[] weekDays;
private SeekBar skbrVolume;
private ToggleButton tglVibration;

// -- Class Events -- //

@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);

    setContentView(R.layout.timespan_definition);

    initializeResources();

    Bundle extras = getIntent().getExtras();

    // Get the time-span Row ID
    mRowId = (extras != null) ? extras.getLong(RVSUtilities.getDefaultPackage() + TimespanScheduleTable.KEY_ROWID)
            : -1;

    populateResources();
}

// -- User Events -- //

public void tglVibration_Click(View v)
{
    if (((ToggleButton) v).isChecked())
    {
        Vibrator vibrate = (Vibrator) getSystemService(VIBRATOR_SERVICE);
        vibrate.vibrate(1000);
    }
}

strings.xml:

<string name="timespanDefinition_tglVibration_Click">tglVibration_Click</string>

Note: The app is targeting Android 2.3.3 specifically Google API version 10

Thank you.

Footmark answered 24/3, 2012 at 15:11 Comment(0)
D
5

What is the cause and solution of this problem?

The cause is your use of a string resource for the method name.

The solution is to get rid of the string resource and to put the method name in the android:onClick attribute directly.

UPDATE: If the markers do not go away, right-click over the project, and choose Android Tools > Clear Lint Markers.

Delorasdelorenzo answered 24/3, 2012 at 16:13 Comment(5)
I changed the onClick attribute to: android:onClick="tglVibration_Click" but was all in vein because the error remained. However it seems like the error didn't update with the new attribute value. I therefore cleaned and rebuild the project and even tried closing and re-opening Eclipse but the error remained the same: "Corresponding method handler 'public void @string/timespanDefinition_tglVibration_Click(android.view.View)' not found" Any ideas?Footmark
@Kurt: No, I would have expected that simply changing the file would have cleared up your problem, let alone cleaning the project or restarting Eclipse. Are you using tglVibration_Click for more than one widget, where you perhaps still have the string resource for another one?Delorasdelorenzo
Unfortunately no, I am not using the same onClick event name for multiple widgets a search in the workspace for tglVibration_Click found only one result. I can't understand how this problem emerged after I updated the Android SDK tools.Footmark
@Kurt: Well, the lint utility definitely changed in R17, so I am not surprised that this issue appeared. I am surprised that your environment does not seem to recover after applying the fix.Delorasdelorenzo
@Kurt: I reproduced your problem and was able to clear the markers -- see the updated answer.Delorasdelorenzo
C
1

Soon after update/install it shows errors. But re-running Lint corrects the problem.

Right Click Project -> Android Tools -> Click "Run Lint: Check for common Errors"

Cl answered 22/4, 2012 at 11:24 Comment(0)
A
1

i had this same problem...

  1. check tools:context=".MainActivity" in your XML wheather its indicating to right java activity
  2. Rebuilt or clean project from build--> clean project in top menu
  3. make sure you have View in your function parameters public void onclickdo(View view)

hope this is help full

Androus answered 27/5, 2018 at 11:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.