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);
}
});
CodePudding user response:
Your app is crashing because you are proving 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);