Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Beard- 0
4,211 PointsSelf-destructing message android app > Sending a Message > App Crash when using Take Picture
Disclaimer: I'm no expert by any means. I merely want to share what I feel might help others with a similar issue.
A lot of you may have run into NullPointerExceptions at line 27 of the FileHelper class or simply found your app crashing when trying to Take Picture and found it weird that Choose Picture and Video worked fine.
From my digging around and debugging, I've found that when the camera is called in some cases the Ribbit activity gets destroyed, so when it returns mMediaUri is null.
The work around that I have used is to save the value using onSavedInstanceState in MainActivity.java
protected void onSaveInstanceState(Bundle outState){
super.onSaveInstanceState(outState);
if(mMediaUri != null){
outState.putString("mediaUri", mMediaUri.toString());
}
}
protected void onRestoreInstanceState(Bundle savedInstanceState){
super.onRestoreInstanceState(savedInstanceState);
if(savedInstanceState.containsKey("mediaUri")){
mMediaUri=Uri.parse(savedInstanceState.getString("mediaUri"));
}
}
I do not know if this was intentionally left out for learning purposes, but it seems to get pretty misleading at times.
I hope Ben Jakuben could either enlighten us with the right woraround or atleast include it in the videos so that the future students don't end up at a stand still.
Thanks in Avance
Beard- 0
4,211 PointsHey Jake barnly ,
Yup I did, did you try using onSavedInstanceState the way I have in my code snippet?
Jake barnly
177 PointsJake barnly
177 PointsHey did you figure this out? I have been trying this question for other apps but no answer from anyone.