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
Contributor
Posts: 17
Registered: ‎05-12-2010
My Device: odin
My Carrier: student

the image can't be shown

[ Edited ]

hi,

i need help. i want to show an image in my aplication. i'm using this code to show it up :

Bitmap logoBitmap = Bitmap.getBitmapResource("resource/test.png");
        bitmapField = new BitmapField(logoBitmap, Field.FIELD_HCENTER);
        add(bitmapField);

 

something wrong in that code?or not every image can be shown?

thanks

Developer
Posts: 1,305
Registered: ‎01-21-2009
My Device: Not Specified

Re: the image can't be shown

The most likely problem is that "resource/test.png" cannot be found, so logoBitmap ends up null and the field displays nothing. The correct string to use depends on where test.png is located in your project tree. The string you are using will look for it inside a folder named "resource" that it expects to find in the package folder for the class in which your code appears. It's more likely that you need to use "/resource/test.png". If you have included the folder "resource" in the project source path, then the correct string is "/test.png".




Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.
Developer
Posts: 92
Registered: ‎01-15-2009
My Device: Blackberry 9550

Re: the image can't be shown

Hi. Try to move your test.png to folder src/res/ in your Blackberry project

 

and use this code EncodedImage.getEncodedImageResource("src/res/test.png");

or Bitmap logoBitmap = Bitmap.getBitmapResource("src/res/test.png");

Developer
Posts: 1,305
Registered: ‎01-21-2009
My Device: Not Specified

Re: the image can't be shown

I think that for dmazgalin's suggestion to work, the resource name will need to be "/res/test.png".

 

When you use a relative name for a resource (one that does not start with a '/'), the system interprets it with respect to the package folder for the class being used to access the resource. An absolute name (one that does start with '/') is interpreted with respect to the root of the packaged project. The root of the package contains the contents of all directories listed as source folders in the build configuration.

 

One way to double-check where a resource ended up in the package (and hence what string to use to access it at run time) is to browse the .jar file. The .jar file is nothing more than a .zip archive, so you can browse it using WinZip, 7-Zip, and similar tools.




Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.
Developer
Posts: 92
Registered: ‎01-15-2009
My Device: Blackberry 9550

Re: the image can't be shown

test.png

if you use Eclipse this works perfectly.

Developer
Posts: 1,305
Registered: ‎01-21-2009
My Device: Not Specified

Re: the image can't be shown

[ Edited ]

 


dmazgalin wrote:

if you use Eclipse this works perfectly.


Did you actually try this? It only worked for me by dropping "src/" from the name of the resource. What's the source path set to for your project?




Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.