我正在使用包含其他对象之间的图像对象的JSON字符串。由此我创建具有PropertyBusinessObject一个下列ClassCastException - java.lang.String不能转换为com.codename1.ui.Image
public final Property<EncodedImage, Profile> profilePic = new Property<>("profilePic", EncodedImage.class);
我创建了一个方法,在PropertyBusinessObject
public EncodedImage getProfilePic() {
return profilePic.get();
}
我填充我的数据到房产业务对象如下:
profile.getPropertyIndex().populateFromMap((Map) profileObject);
当我尝试使用以下代码在窗体上显示图像时,
ScaleImageLabel profilePic = new ScaleImageLabel(profile.getProfilePic()) {
@Override
protected Dimension calcPreferredSize() {
Dimension dimension = super.calcPreferredSize();
dimension.setHeight(Math.min(dimension.getHeight(), Display.getInstance().convertToPixels(40)));
return dimension;
}
};
profilePic.setBackgroundType(Style.BACKGROUND_IMAGE_SCALED_FILL);
container.add(BorderLayout.NORTH, profilePic);
我得到一个ClassCastException
例外:java.lang.ClassCastException - java.lang.String中不能转换到com.codename1.ui.Image
谁能帮我解决,或建议消费JSON字符串的另一种方式?
图像的格式是什么? BASE64? – Diamond
图像是Base64 – Rootsman