2011-05-07 63 views
2

我只是性学习的如何将黑莓程序,并试图在屏幕上显示位图的位图,这里是代码:试图借鉴黑莓

public MyScreen() 
{   
    // Set the displayed title of the screen  
    setTitle("MyTitle2"); 
    LabelField lb = new LabelField("hello ted2"); 
    add(lb); 

    Bitmap logoBitmap = Bitmap.getBitmapResource("res/icon2.png"); 
    BitmapField fd= new BitmapField(logoBitmap, Field.FIELD_HCENTER); 
    add(fd); 
} 

标签被绘制而不是位图。

回答

1

我认为你需要把两个字段为VerticalFieldManager

public MyScreen() 
{   
    VerticalFieldManager vfm = new VerticalFieldManager(); 

    // Set the displayed title of the screen  
    setTitle("MyTitle2"); 
    LabelField lb = new LabelField("hello ted2"); 
    vfm.add(lb); 

    Bitmap logoBitmap = Bitmap.getBitmapResource("res/icon2.png"); 
    BitmapField fd= new BitmapField(logoBitmap); 
    vfm.add(fd); 

    add(vfm); 
} 
+0

嗨,谢谢你回答我的quastion,但是......它仍然不起作用。 – 2011-05-07 12:04:14

+0

确保您的PNG文件路径正确。如果不是,我认为'getBitmapResource'只返回'null',所以不会抛出异常。 – MusiGenesis 2011-05-07 13:32:55

2

你的道路是错误的,将图像复制到/ RES/IMG。要检索它,请仅使用文件名。

Bitmap logoBitmap = Bitmap.getBitmapResource("icon2.png");