无法从 OnClickListener 启动 Andengine Activity

Trouble launching Andengine Activity from OnClickListener

我有一个 Activity 仅用于显示主菜单,然后我想在单击按钮后启动一个 Andengine Activity。

public class MainMenuActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_menu_layout);

        TextView nadpis = (TextView) findViewById(R.id.nadpis);
        Typeface tf = Typeface.createFromAsset(getAssets(), "font/DiamondsPearls.ttf");
        nadpis.setTypeface(tf);

        Button playGame = (Button)findViewById(R.id.playgame);
        playGame.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(this, MonsterTap.class);
                startActivity(intent);
            }
        });
    }

}

我看到一条关于行 Intent intent = new Intent(this, MonsterTap.class); 的错误

cannot resolve constructor intent(anonymous android.view.View.OnClickListener, java.lang.class)

我做错了什么?

Intent intent = new Intent(this, MonsterTap.class); 替换为 Intent intent = new Intent(MainMenuActivity.this, MonsterTap.class); 以正确传递意图 Context

如您所写,this 关键字指的是代表您的 OnClickListener.

的匿名内部 class