2017-10-16 64 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天內出現,因此可能不需要解決方法 –

相關問題