OnClickListener cannot be resolved to a type (Eclipse)

喜欢而已 提交于 2019-12-05 05:43:40

For starters, it's always best to let Eclipse manage all imports by tapping Ctrl+Shift+O when you see an import error.

It seems that your problem is due to:

import android.view.view;

Which should be:

import android.view.View;

Same goes with android.view.View.OnClickListener.

If you remove the two lines you've manually added and hit Ctrl+Shift+O, everything should fix itself.

zamil nizar

Add

import android.view.View.OnclickListener

to your import section and it should work.

The second "view" in the import statement is a class (hence, OnClickListener is an inner class/interface) and should be capitalised:

import android.view.View.OnClickListener;

make sure your class implements OnClickListener

public class main extends Activity implements OnClickListener {

if you still have error you can make the class abstract like this public abstract class MainActivity extends Activity implements OnClickListener {

If you are using the new Android Studio you must declare your new OnClickListener as View.OnClickListener. Otherwise Android Studio gets confused and won't understand.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!