使用JavaFX创建桌面应用程序,该应用程序从API获取用户列表,其中包含每个用户配置文件图像的URL,一些图像从服务器加载,另一些图像从Facebook加载。应该从Facebook加载的图像的URL是使用Facebook图形构建的。但是,在浏览器中图像正常加载,但在应用程序中我必须做错事。
我正在将这些图像加载到地图中,所以我不必每次都请求图像,这里是代码:
/**
* @author Asendar
*
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class UserAvatarModel {
/**
*
*/
private static final Log LOG = LogFactory.getLog(UserAvatarModel.class);
/**
* default avatar (use when user has no image)
*/
public static final Image DEFAULT_IMAGE = ImageLoader.instance.loadImage("default-avatar");
/**
* caching the images
*/
private static final Map<String, Image> IMG_MAP = new HashMap<>();
/**
* @param user
* @return
*/
public static Image getUserAvatar(User user) {
if (user.getAvatarUrl() == null)
return DEFAULT_IMAGE;
Image img = IMG_MAP.get(user.getAvatarUrl());
if (img == null) {
LOG.debug("registering new image, URL : " + user.getAvatarUrl());
img = new Image(user.getAvatarUrl());
LOG.debug("image loaded ? : " + (img.isError() ? "ERROR" : "SUCCESS"));
IMG_MAP.put(user.getAvatarUrl(), img);
}
return img;
}
}
问题是img.isError()
适用于所有包含网址的图片:http://graph.facebook.com
控制台(用xxxxxxxx替换了id)在浏览器上正常加载:
01:44:50,983 DEBUG com.ro.terminal.model.user.UserAvatarModel : registering new image, URL : http://graph.facebook.com/v1.0/xxxxxxxx/picture?type=large
01:44:51,382 DEBUG com.ro.terminal.model.user.UserAvatarModel : image loaded ? : ERROR
01:44:52,371 DEBUG com.ro.terminal.model.user.UserAvatarModel : registering new image, URL : http://graph.facebook.com/v1.0/xxxxxxxx/picture?type=large
01:44:52,526 DEBUG com.ro.terminal.model.user.UserAvatarModel : image loaded ? : ERROR
01:44:53,826 DEBUG com.ro.terminal.model.user.UserAvatarModel : registering new image, URL : https://lh3.googleusercontent.com/-Dus_SnL_n7Y/AAAAAAAAAAI/AAAAAAAAAAA/1nLwm-HfoBs/photo.jpg?sz=50
01:44:55,442 DEBUG com.ro.terminal.model.user.UserAvatarModel : image loaded ? : SUCCESS