Tomas Mota
Tomas Mota

Reputation: 679

Method does not override method from its superclass error

Only this @Override method is getting an error. Although, every other @Override method is fine. I am not getting the same error on those.

Any help is appreciated.

@Override
public void onClick(View v) {
    int i = v.getId();
    if (i == R.id.Register) {
        createAccount( mEmailView.getText().toString(), mPasswordView.getText().toString() );
    } else if (i == R.id.Login){
        Intent in = new Intent( LoginActivity.this, LoginActivity2.class );
        startActivity(in);

    }
}

Upvotes: 0

Views: 1944

Answers (2)

guipivoto
guipivoto

Reputation: 18677

You are receiving a warning because the @Override annotation is wrongly inserted on that method.

There's no OnClick(View v) method on parent class. So, you can't override a method that does not exist on parent class.

Just remove the @Override and that warning should go:

// @Override --> Remove this
public void onClick(View v) {
    int i = v.getId();
    if (i == R.id.Register) {
        createAccount( mEmailView.getText().toString(), mPasswordView.getText().toString() );
    } else if (i == R.id.Login){
        Intent in = new Intent( LoginActivity.this, LoginActivity2.class );
        startActivity(in);

    }
}

Upvotes: 2

Arnab Banerjee
Arnab Banerjee

Reputation: 165

I think you are trying to implement an onClickListener. You should implement the View.OnClickListener interface in your activity.

public class YourActivityName extends AppCompatActivity implements View.OnClickListener

Then in the onCreate() method you can use yourButton.setOnClickListener(this);

As I read in the comments, to start an activity from the register button do this outside onCreate:

Button registerBtn;

Inside onCreate method do this:

registerBtn=findViewById(R.id.register);
registerBtn.setOnClickListener(this);

Inside onClick method do this:

if(v.equals(registerBtn))
{
Intent intent=new Intent(getApplicationContext(),OtherActivity.class);
startActivity(intent);
finish();
}

Upvotes: 0

Related Questions