How do I get my Android Intent to work properly?

23 Views Asked by At

I am making an intent for my application, however, everytime I enter my context, the IDE errors with java compilation errors. I have no idea how to fix this. Please help.

Code for MainActivity.java:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    final FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    assert fab != null;
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent myIntent = new Intent(this, SecondActivity.class);
            startActivity(myIntent);
        }
    });
}

Please help. I am attempting to code for Android 2.2 Froyo using Android Studio 1.5.2.

1

There are 1 best solutions below

0
Peer Mohamed On
Intent myIntent = new Intent(MainActivity.this, SecondActivity.class);

instead of

Intent myIntent = new Intent(this, SecondActivity.class);