Superunknown
Superunknown

Reputation: 501

What can I do when I get a "cannot be resolved to a type" error?

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

Answers (5)

Saugat Bhattarai
Saugat Bhattarai

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

slhck
slhck

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

Jaydeep Khamar
Jaydeep Khamar

Reputation: 5985

Use

this.insertionButton.setOnClickListener(new View.OnClickListener){});

and yes also import the above mentioned classes or press ctrl+shift+o

Upvotes: 1

Lukas Knuth
Lukas Knuth

Reputation: 25755

From the Android API:

button.setOnClickListener(new View.OnClickListener()

Upvotes: 1

Nikhil
Nikhil

Reputation: 16196

import android.view.View.OnClickListener;

import this

Upvotes: 2

Related Questions