I am running ProfileActivity which calls the GalleryActivity:
but I am getting the below error\
what is happening and how should I solve it?
CodePudding user response:
Your problem is that inside the anonymous object View.OnClickListener(){ /*inside here */ } the keyword this reference to the anonymous object itself, you need to get the reference of the Activity by using ProfileActivity.this
Note: Your GalleryActivity will throw SuperNotCalledException, add super.onCreate(savedInstanceState) to it in the overrided onCreate
CodePudding user response:
I see two problems in your code.
The first one is that you're using the this keyword inside an OnClickListener, passing it to your Intent. Intents take a reference to an Activity, but the this inside the listener refers to the listener itself.
To solve this, you can just change this to ProfileActivity.this.
The second problem is in GalleryActivity: in the onCreate() method, you're not calling super.onCreate(savedInstanceState), but you should.



