Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Regular Contributor
Posts: 58
Registered: ‎10-21-2010
My Device: Bold 9700
My Carrier: DTAC
Accepted Solution

GIFEncodedImage in BlackBerry OS7

I got a problem on BlackBerry JRE 7.0 when I tried to show Custom Dialog. It show ClasscastException on a Simulator screen when I debugged  my code I found that it carshed when I trying to use GIFEncodedImage and this is my code:

 

package com.codemobiles.bb.thaidict;

import com.codemobiles.bb.thaidict.custom.field.AnimatedGIFField;

import net.rim.device.api.system.GIFEncodedImage;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.Keypad;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.PopupScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;

public class LoadingScreen extends PopupScreen implements FieldChangeListener{
  
  protected boolean keyChar(char c, int status, int time) {
    // TODO Auto-generated method stub
    if (c == Keypad.KEY_ESCAPE) {
      close();
      return true;
    }
    return true;
  }
  
  public ButtonField dissmissButton;
  public LoadingScreen(VerticalFieldManager delegate){
    super(delegate);
    HorizontalFieldManager loadingManager = new  HorizontalFieldManager(Manager.FIELD_HCENTER);
    GIFEncodedImage image = (GIFEncodedImage) GIFEncodedImage.getEncodedImageResource("img/load.gif");
    AnimatedGIFField gifField = new AnimatedGIFField(image,Field.FIELD_HCENTER);
    LabelField loadingLabel = new LabelField("Being Translated..");
    dissmissButton = new ButtonField("Cancel",Field.FIELD_HCENTER);
    gifField.setMargin(4, 10, 0, 0);
    loadingManager.setMargin(0, 0, 7, 0);
    
    loadingManager.add(gifField);
    loadingManager.add(loadingLabel);
    add(loadingManager);
    add(dissmissButton);
    dissmissButton.setChangeListener(this);
  }
  // TODO Auto-generated constructor stub}

  public void fieldChanged(Field field, int context) {
    // TODO Auto-generated method stub
    if(field == dissmissButton){
      close();
    }
  }

}

 It carshed at this line:

GIFEncodedImage image = (GIFEncodedImage) GIFEncodedImage.getEncodedImageResource("img/load.gif");

 This code is work fine on BlackBerry OS 5 - 6.

Does anyone know about this problem and the way to fix it?

 

Thanks,

Regards

Developer
Posts: 152
Registered: ‎07-28-2011
My Device: Bold 9900
My Carrier: MTN

Re: GIFEncodedImage in BlackBerry OS7

What happens if you remove the cast when calling:

 

GIFEncodedImage image = (GIFEncodedImage) GIFEncodedImage.getEncodedImageResource("img/load.gif");



Super Contributor
Posts: 278
Registered: ‎11-04-2010
My Device: 4.5 and above
My Carrier: none

Re: GIFEncodedImage in BlackBerry OS7

hI,
I THINK img is a folder where u have your gif file..
just give the name.. like this ("load.gif") instead of ("img/load.gif")
Thanks & Regards
pp
Regular Contributor
Posts: 58
Registered: ‎10-21-2010
My Device: Bold 9700
My Carrier: DTAC

Re: GIFEncodedImage in BlackBerry OS7

If I remove this line, these codes can run with no runtime error but the gif image will not show.

Regards

Regular Contributor
Posts: 58
Registered: ‎10-21-2010
My Device: Bold 9700
My Carrier: DTAC

Re: GIFEncodedImage in BlackBerry OS7

You're right "img" is a image folder. I don't understand why you think ("load.gif") will be work?

 

FYI. This code is work fine on BlackBerry OS5 and 6.

Developer
Posts: 152
Registered: ‎07-28-2011
My Device: Bold 9900
My Carrier: MTN

Re: GIFEncodedImage in BlackBerry OS7

For OS7 have you tried removing the casting to gif to see what is returned?

 

GIFEncodedImage image = GIFEncodedImage.getEncodedImageResource("img/load.gif");

 

New Contributor
Posts: 7
Registered: ‎07-21-2011
My Device: 9800
My Carrier: Telus

Re: GIFEncodedImage in BlackBerry OS7

I've got the same problem.

It returns a PNGEncodedImage.
New Developer
Posts: 7
Registered: ‎08-05-2011
My Device: 9900
My Carrier: developer

Re: GIFEncodedImage in BlackBerry OS7

Rename the GIF file in the resource with extension .agif.

This works in my code. Try this.

New Contributor
Posts: 7
Registered: ‎07-21-2011
My Device: 9800
My Carrier: Telus

Re: GIFEncodedImage in BlackBerry OS7

Thanks Afftar, worked a charm.
Highlighted
Developer
Posts: 1,807
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.3.2.858, Z10 (STL100-3)-10.3.1.2576, Z30 (STA100-5)-10.3.1.2582, Passport (SQW100-1)-10.3.1.2576, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: GIFEncodedImage in BlackBerry OS7

The sub-issue that ptuckey posted may be the problem that you are facing.

 

Though I have not done any testing on the defaults, check to make sure that "Convert image files to png" is unchecked (it's located in the Application Descriptor XML file under the "Build" submenu).

 

BlackBerry (and J2ME in general)'s default (and perferred) image format is PNG. rapc, when that option is checked, will convert the images (based on extension) and leave the file names the same.

 

That is why ptuckey was able to change his/her extension and resolve the issue.

 

Under OS 5 and 6, this should be unchecked by default. I don't know if that changed for OS 7.

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.