App keeps crashing after moving to new page

Viewed 55

I have the following code in android studio. I would like to move to a new page in android but the app keeps crashing, any idea?

lst1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            
            Toast.makeText(getApplicationContext(),"test",Toast.LENGTH_LONG).show();
           
            Intent intent = new Intent(getApplicationContext(), com.example.courseregapp.View.class);
           
            startActivity(intent);
        }
    });
1 Answers

Your app is crashing because you are providing application context to intent instead of providing class context. Your code should be like this.

Intent intent = new Intent(YourCurrentClassName.this, View.class);
       
startActivity(intent);
Related