Ala*_*Lai 1 blackberry popup classcastexception
我打电话给这个班级PopupScreen
.
public class Custom_LoadingScreen extends PopupScreen {
private VerticalFieldManager vfm;
private Util_AnimateGifField anmtFldCycle = null;
private GIFEncodedImage gifImgCycle;
public Custom_LoadingScreen() {
super(new VerticalFieldManager());
Background bg = BackgroundFactory.createSolidTransparentBackground(
Color.BLACK, 190);
setBackground(bg);
setBorder(BorderFactory.createSimpleBorder(new XYEdges(),
Border.STYLE_TRANSPARENT));
gifImgCycle = (GIFEncodedImage) GIFEncodedImage
.getEncodedImageResource("LoadingSpinner.gif");
anmtFldCycle = new Util_AnimateGifField(gifImgCycle,
Field.FIELD_HCENTER);
vfm = new VerticalFieldManager(USE_ALL_WIDTH) {
protected void sublayout(int maxWidth, int maxHeight) {
super.sublayout(Display.getWidth(), Display.getHeight());
setExtent(Display.getWidth(), Display.getHeight());
}
};
int padding = (Display.getHeight() - 16) / 2;
if (padding > 0) {
anmtFldCycle.setPadding(padding, 0, 0, 0);
}
vfm.add(anmtFldCycle);
add(vfm);
}
//public void Popupscreen() {
//Main.getUiApplication().popScreen(this);
//}
public boolean keyDown(int keycode, int status) {
if (Keypad.key(keycode) == Keypad.KEY_ESCAPE) {
Main.getUiApplication().popScreen(this);
return true;
}
return super.keyDown(keycode, status);
}
}
Run Code Online (Sandbox Code Playgroud)
在按钮中,我按下它然后转到下一个屏幕.
financebtn = new Custom_ButtonField(finance, financeactive,
financeactive) {
protected boolean navigationClick(int status, int time) {
Main.getUiApplication().pushScreen(new Custom_LoadingScreen());
Main.getUiApplication().invokeLater(new Runnable() {
public void run() {
// Main.getUiApplication().popScreen();
Main.getUiApplication().pushScreen(
new Main_NewsDetail());
}
}, 1 * 1000, false);
return true;
}
};
add(financebtn);
Run Code Online (Sandbox Code Playgroud)
结果给了我Uncaught:ClassCastException
.我可以调用另一个类似于custom_loadingscreen
popupscreen的类.它工作正常.
我也试过在另一个按钮中调用这个类,但仍然是同样的问题.
如果你看看你的Custom_LoadingScreen
代码,你只有一个地方在做一个演员:
gifImgCycle = (GIFEncodedImage) GIFEncodedImage
.getEncodedImageResource("LoadingSpinner.gif");
Run Code Online (Sandbox Code Playgroud)
所以,这是一个开始寻找的好地方.如果你谷歌为"BlackBerry GIFEncodedImage ClassCastException",你会发现这个线程:
问题是,为了优化,BlackBerry喜欢将图像转换为PNG格式,而大多数智能手机最适合这种格式.所以,这里发生的是你的GIF图像实际上被转换为PNG图像.因此,当您调用该getEncodedImageResource()
方法时,您要返回的对象实际上可能是类型PNGEncodedImage
,而不是GIFEncodedImage
,并且您获得了异常.偷偷摸摸,是吗?
你可以通过几种方式解决它.
PNGEncodedImage
,或者像这样测试对象:EncodedImage img = EncodedImage.getEncodedImageResource("LoadingSpinner.gif");
if (img instanceof GIFEncodedImage) {
// cast to GIFEncodedImage
} else if (img instanceof PNGEncodedImage) {
// cast to PNGEncodedImage
}
Run Code Online (Sandbox Code Playgroud)
数字(1)将失去所有非PNG图像的非PNG到PNG转换优化,而不仅仅是这个.
数字(2)确实看起来有点难看.但是,这样做的好处是,您可以仅为这一个图像禁用此行为.如果您的大部分图像都不是PNG图像,那么让BlackBerry为您优化其他图像可能很有价值.但是,也许这个人需要成为GIF.所以,#2允许你作为一个特例来处理这个.
我只是猜测这张图片可能是动画 GIF吗?是对的吗?如果是这样,您可能希望将其保留为GIF,因此您不希望使用数字(3),这可以将其转换为PNG,并将其用作此类.
归档时间: |
|
查看次数: |
236 次 |
最近记录: |