user1784961
user1784961

Reputation: 57

App crashes when file path is null

Hi when I do File file = new File(tempPath) app is crashing when tempPath is empty

File file = new File(tempPath);
if (!file.isFile());

Upvotes: 0

Views: 133

Answers (1)

Blackbelt
Blackbelt

Reputation: 157467

Because it accessing a invalid location on the hard memory of the device. If you are fortunate he will try to access "/". To avoid this you should check if tempPath is empty this way:

if (TextUtils.isEmpty(tempPath)) {
}

isEmpty will return true both it the string is empty or null

Upvotes: 1

Related Questions