BlackBerry Forums Support Community               

Closed Thread
LinkBack Thread Tools
Old 12-19-2007, 05:04 AM   #1 (permalink)
New Member
Join Date: Dec 2007
Model: 7100T
Carrier: GPRS
Posts: 5
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Displaying an image on the screen

Please Login to Remove!

Hi All,

I need to display an image on the screen. This is what i am doing

Bitmap img = Bitmap.getBitmapResource("/image.png");
BitmapField bf = new BitmapField(img, BitmapField.FOCUSABLE);

My project is at created at C:\Program Files\Research In Motion\BlackBerry JDE 4.2.1\bin.

My jar file and image are in the same folder.

From the BlackBerry JDE i have added the image to the project. still it shows file not found.

where do i need to place the image in my project?

Please help.
Old 12-19-2007, 08:11 AM   #2 (permalink)
Thumbs Must Hurt
Join Date: May 2007
Location: Bulgaria
Model: none
Carrier: Mtel
Posts: 150
Post Thanks: 0
Thanked 0 Times in 0 Posts

See at getResourceAsStream() method of java.lang.Class in the RIM Device Java Library. In my project (i am using eclipse) my source code and my resources are compiled through ant build in one folder so that the main class of the application is in the same folder with the images. I use a code like this:
  private static byte[] readResourceBytes(String resourceName) {
    try {
      InputStream is = Class.forName(MAIN_CLASS).getResourceAsStream(
      int length = is.available();
      byte[] resourceBytes = new byte[length];;
      return resourceBytes;
    } catch (Exception exc) {
    return null;

//load the image like this:

byte[] imageBytes = readResourceBytes(imageName);
EncodedImage image = EncodedImage.createEncodedImage(imageBytes, 0,
Good luck !
Old 12-19-2007, 08:40 AM   #3 (permalink)
CrackBerry Addict
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Post Thanks: 0
Thanked 0 Times in 0 Posts

getBitmapResource should work. Try it without the backslash
java developer, Devinto, hamburg/germany
Closed Thread

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

APPLE 820-0522-A 630-0895-B LITE VRAM 128K X 8 BOARD
APPLE 820-0522-A 630-0895-B LITE VRAM 128K X 8 BOARD   picture

Copyright 2004-2016
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.