0

Kindly someone explain, why is it not working?

b3.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Intent intent = new Intent(this, signup.class);
        startActivity(intent);                
    }
});

signup word is giving error in the line given below.

Intent intent = new Intent(this, signup.class);
moffeltje
  • 4,521
  • 4
  • 33
  • 57
Daniyal
  • 37
  • 1
  • 7

3 Answers3

0

If your current activity is called Main use:

Intent intent = new Intent(Main.this, signup.class);

When you put only this, this is reference of the OnClickListener object.

Dreo
  • 229
  • 5
  • 12
0

Use Classname.this

For example:

Intent _intent = new Intent(MainActivity.this , signup.class ) ;

Next time , pls try to come up with some logs/error description

Vivek_Neel
  • 1,343
  • 1
  • 14
  • 25
0
Intent intent = new Intent(this, signup.class);

Should be like this: Intent intent = new Intent(YouCurrentActivity.this, signup.class); Replace YouCurrentActivity with the name of the activity that you are currently coding in. The error occurs because you cannot refer to the Activity name with "this" in an inner class. e,g in an onClickListener.

Regards from Iran, Gabriel