Java – class must be declared abstract or implement abstract method error

Here's my code. Suppose you change some text when you press the button: –

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 is underlined and gives the error "class must be declared abstract or implement abstract method" Most of this code is copied from the Internet. It is assumed to work normally Maybe it's just an Android studio error How can I make it work?

Solution

View. Onclicklistener must implement onclick() function, otherwise your class should be abstract, so you can implement onclick() function in a subclass But in your case, you misspelled It should be onclick() instead of onclick();

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>