Activity used to start app doesn't exist or cannot be launched! Make sure it exists and is a launchable activity

I have this interesting issue that I am encountering. I was able to write a code to access webview of the hybrid app and automate it. However, half of the time upon running the code I get the activity could not be launched. I have restarted the sever but it only works intermittently. If I comment out the code and only use the code to launch the app,I never run into that issue.