How do I know if a Uri is empty?

Alex Voicu picture Alex Voicu · Feb 26, 2015 · Viewed 12.6k times · Source

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.

Answer

Stanislav Bodnar picture Stanislav Bodnar · Feb 26, 2015

Just check that Empty URI is not equal to followUri, this check includes check by null:

        if (!Uri.EMPTY.equals(followUri)) {
            //handle followUri
        }