android - Java string comparison fails -


i've been looking mistake in code hours can't find it. locate mistake in part of code:

public string gettype(file file) {     string type = null;      try     {         type = urlconnection.guesscontenttypefromname(file.getabsolutepath());         if (type.startswith("image"))         {             log.d(logtag, file.getabsolutepath());         }     }     catch (exception e){}      return type; } 

this works absolutely fine when string comparison directly before return statement don't types start "image".

the same thing happens when don't use exception handling block.

i've displayed integer values of string , equal.

in case matters: android project.

edit: e.g

/storage/emulated/0/whatsapp/media/whatsapp images/img-20150906-wa0000.jpg 

in both cases whereas receive

/storage/emulated/0/profilbilder/18186367897.jpg 

only when use code above. , no exception thrown file.

edit: created new project , works expected now. since new code not same almost, can't tell whether logical mistake or compiler

when file null or urlconnection throws exception, type must null, there nullpointerexception on type.startswith("image")


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -