10-31-2010 06:12 AM - edited 10-31-2010 06:13 AM
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);
something wrong in that code?or not every image can be shown?
10-31-2010 12:51 PM
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".
11-01-2010 01:28 AM
Hi. Try to move your test.png to folder src/res/ in your Blackberry project
and use this code EncodedImage.getEncodedImageResource("src/res/test
or Bitmap logoBitmap = Bitmap.getBitmapResource("src/res/test.png");
11-01-2010 12:46 PM
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.
11-01-2010 05:03 PM - edited 11-01-2010 05:04 PM
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?