类必须声明为抽象或实现抽象方法错误 [英] Class must either be declared abstract or implement abstract method error

查看:69
本文介绍了类必须声明为抽象或实现抽象方法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码,假设在按下按钮时更改一些文本:-

This is my code that is suppose to change some text on button press:-

public class MyActivity extends ActionBarActivity {
    TextView txtview;
    Button butto;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my);
        ImageView imageView = (ImageView) findViewById(R.id.image);
        txtview = (TextView) findViewById(R.id.text);
        butto = (Button) findViewById(R.id.buttn);

        butto.setOnClickListener(new View.OnClickListener() {

                public void Onclick(View paramView) {
                txtview.setText("You Clicked it!");
            }
        });

    }}

View.OnClickListener 带有下划线,它给了我错误类必须声明为抽象或实现抽象方法".这段代码大部分是从互联网上复制的,它应该可以正常工作.可能只是 Android Studio 错误.我怎样才能让它工作?

The View.OnClickListener is underlined and it gives me the error "Class must either be declared abstract or implement abstract method". This code has been mostly copied from the internet and its suppose to be working fine. Probably its a Android Studio error only. How can I get it to work?

推荐答案

View.OnClickListener 必须实现函数 onClick() 否则你的类应该是抽象的,这样你可以在一些子类中实现你的 onClick() 函数.但是在您的情况下,您犯了拼写错误.它应该是 onClick() 而不是 Onclick();

View.OnClickListener must implement the function onClick() otherwise your class should be abstract, so that you could implement your onClick() function in some child class. But in your case you have made a spelling mistake. It should be onClick() instead of Onclick();

这篇关于类必须声明为抽象或实现抽象方法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆