Issue
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);
}
});
Solution
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);
Answered By - Nur Alam
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.