Reputation: 501
I am trying to create a button on the mainActivity
. Once clicked, it takes a user to a second view. However I keep getting an error saying that
onclick listener cannot be resolved to a type
and
the method set onclicklistener in the type view is not applicaible for the type of arguments
Below is the screenshot of the code:
Does anyone have any ideas?
Upvotes: 3
Views: 10077
Reputation: 2750
Use class name you may have mistaken using xml name ... For example:
public void onClick(View v) {
startActivity(new Intent(Second.this, Third.class));
}
You may have used "third.class"
public void onClick(View v) {
startActivity(new Intent(Second.this, third.class));
}
Upvotes: 3
Reputation: 38652
This is because your source file is still missing the required imports for the classes you want to use.
You can always auto-add missing imports using Eclipse:
Ctrl+Shift+O
That way you don't have to guess which package you need to import.
Upvotes: 10
Reputation: 5985
Use
this.insertionButton.setOnClickListener(new View.OnClickListener){});
and yes also import the above mentioned classes or press ctrl+shift+o
Upvotes: 1
Reputation: 25755
From the Android API:
button.setOnClickListener(new View.OnClickListener()
Upvotes: 1