I am creating an application where the first activity calls the second activity for results i.e startActivityForResult(intent,SELECT_FILE); but on going to second activity if i press the back button of my emulator it throws a exception :
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=0, data=null} to activity {com.upload/com.upload.FileUploadActivity}: java.lang.NullPointerException
what should i do..?
Thankx
When you start a new activity using
startActivityForResulta result is expected when the new activity ends. Normally the new activity is ended and the result is defined in thefinish()method.What I suspect is happening is you do not process the back button press in the new activity and as such no result is generated. Then when the ‘onActivityResult()
is called in the old activity there is no activity to process and you are getting theNullPointerException`.You can solve this one of two ways.
In the new activity Listen for the back button press and when it is pressed call
finish()to setup the result. Or in the old activity check the result to make sure it is valid and isn’t null (You should really be doing this anyway)