Vserv LWUIT banner

67 Views Asked by At

i am getting a ClassCastException when i try to cast to cast into com.sun.lwuit.Image .Please help on how i can change the code below to use in LWUIT

public void vservAdReceived(Object obj)
     {

         if(obj==vservAd)
         {

             if(((VservAd)obj).getAdType().equals(VservAd.AD_TYPE_IMAGE))
             {
                 com.sun.lwuit.Image imageAd=(com.sun.lwuit.Image)((VservAd)obj).getAd();
                 //use image as com.sun.lwuit.Button icon
             }
             else if(((VservAd)obj).getAdType().equals(VservAd.AD_TYPE_TEXT))
             {
                String textAd=(String)((VservAd)obj).getAd();
               //use image as com.sun.lwuit.Button text
             }

         }

     }
1

There are 1 best solutions below

0
On

Probably you get a standard java-me image, and not a LWUIT image. There is a method in lwuit to convert it. From the documentation:

public static Image createImage(java.lang.Object nativeImage)

creates an image from the given native image (e.g. MIDP image object)

You can try it like this:

javax.microedition.lcdui.Image imageAdMe = 
    (javax.microedition.lcdui.Image)((VservAd)obj).getAd();

com.sun.lwuit.Image imageAd = com.sun.lwuit.Image.createImage(imageAdMe);