开发者

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:

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

Does any开发者_如何转开发one have any ideas?


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.


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));
}


import android.view.View.OnClickListener;

import this


From the Android API:

button.setOnClickListener(new View.OnClickListener()


Use

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

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜