onClickListener cannot be resolved to a type and not applicable

前端 未结 5 1983

New to Java, using Eclipse. Except this error I also got some:

Description Resource Path Location Type The method onClick(View) of type new onClickListener

5条回答
  •  生来不讨喜
    2020-12-22 09:14

    Try this:

     Button button1 ,button2;
    
        @Override
                public void onCreate(Bundle SavedInstanceState) {
                    super.onCreate(SavedInstanceState);
                    setContentView(R.layout.activity_main);
                    button1 = (Button)findViewById(R.id.button1);
                     button2 = (Button)findViewById(R.id.button2);
    
                    button1.setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            button1.setText("xyz");
                        }
                    });
         button2.setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            button2.setText("abc");
                        }
                    });
        }
    

提交回复
热议问题