2017-10-16 62 views
1

我正在使用包含其他对象之间的图像对象的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字符串的另一种方式?

+0

图像的格式是什么? BASE64? – Diamond

+0

图像是Base64 – Rootsman

回答

1

populateFromMap目前不支持Base64图像,我会添加该选项作为该用例的意义。星期五更新应该在那里。

+0

谢谢Shai。非常感激。在此期间,你能否给我一些指导,以便我还能实现同样的目标? – Rootsman

+0

您可以浏览地图并使用Base64解码将图像替换为图像。无论哪种方式,它将在2天内出现,因此可能不需要解决方法 –

相关问题