2011-05-07 53 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");