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

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

问题描述

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

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() else your class should be abstract, so that you could implement your onClick() function in some child class.

but in your case you are making spelling mistake. It should be onClick instead Onclick();

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

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