How do I stop a ball from crashing the app when it hits the edge of the canvas?

How do I stop a ball from crashing the app when it hits the edge of the canvas?

2 posts were merged into an existing topic: How to shoot a ball without making my App Crash?