In the following code I check whether or not the given url ends with an allowed filetype (possible types: .jpg, .jpeg, .png & .gif). The list of types are saved in an arraylist which holds the textual description from the UI (e.g. "JPG Images").
My intention is to make the function traverse trough the list with descriptions and check the url with their corresponding URL check methods.
I expected this code to work as I believe that every scenario has been accounted for: if it's JPG, PNG or GIF it returns true, otherwise it returns false. It remains with an error though:
Exception in thread "AWT-EventQueue-0" java.lang.Error: Unresolved compilation problem:
This method must return a result of type boolean
Which obviously means that the returns somewhere have gone wrong. What am I overlooking?
private boolean isImageURL(ImageURL url) {
for (String type : fileTypes) {
if (type.equalsIgnoreCase("JPG Images")) {
if (url.isJPG() || url.isJPEG()) {
return true;
}
} else if (type.equalsIgnoreCase("PNG Images")) {
if (url.isPNG()) {
return true;
}
} else if (type.equalsIgnoreCase("GIF Images")) {
if (url.isGIF()) {
return true;
}
} else {
return false;
}
}
}