Fixing NullPointerException when connection or url is null