I have an application where I need to be able to let the user decide how to put a picture profile, (camera or gallery). I have only one variable of type "Uri" but I do not understand how to reset it and make it EMPTY, or check if it is EMPTY. Because when I choose a picture I have to have the ability to change the photo if you do not like the one just put.
I have tested as
if (followUri.equals (Uri.EMPTY)) {...}
but the application crashes with a null point exception.
Just check that Empty URI is not equal to followUri, this check includes check by null
:
if (!Uri.EMPTY.equals(followUri)) {
//handle followUri
}
If the Uri itself is null then calling followUri.equals(Object) will result in a NPE. A better solution:
if (followUri != null && !followUri.equals(Uri.EMPTY)) {
//doTheThing()
} else {
//followUri is null or empty
}
If your app crashes with an NPE at that stage followUri
is most likely null
.
Also Uri
objects are immutable, see here http://developer.android.com/reference/android/net/Uri.html so you cannot "reset" it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With