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
Trusted Contributor
Posts: 105
Registered: ‎02-02-2011
My Device: Bold 9900
My Carrier: Airtel

Select images dynamically for Bitmap

I want to select image dynamically

from two folders "img1" and "img2" , both are in main image folder

how i access the images in that folders

 

Now am using the following , but i got null pointer Exception

 

 

Bitmap icon = Bitmap.getBitmapResource("/img1/cotg.png");

 

Bitmap icon2 = Bitmap.getBitmapResource("/img2/cotg.png");

Developer
Posts: 1,055
Registered: ‎01-25-2009
My Device: BlackBerry Bold 9650/BlackBerry Torch 9800

Re: Select images dynamically for Bitmap

Try removing the slash before img1 and img2.

Jerome Carty - Follow jcarty on Twitter@jcarty | #webworks-dev / #BlackberryDev on irc.freenode.net | My Apps
Click "Accept as Solution" if post solved your original issue.. Give like/thumbs up if you feel post is helpful
Trusted Contributor
Posts: 105
Registered: ‎02-02-2011
My Device: Bold 9900
My Carrier: Airtel

Re: Select images dynamically for Bitmap

I tried the following options

 

 

Bitmap icon = Bitmap.getBitmapResource("/img1/cotg.png");

Bitmap icon = Bitmap.getBitmapResource("img1/cotg.png");

Bitmap icon = Bitmap.getBitmapResource("images/img1/cotg.png");

Bitmap icon = Bitmap.getBitmapResource("/images/img1/cotg.png");

 

all are failed

 

 

Developer
Posts: 1,055
Registered: ‎01-25-2009
My Device: BlackBerry Bold 9650/BlackBerry Torch 9800

Re: Select images dynamically for Bitmap

Where is your images folder? Is it under the res source folder in Eclipse or is it under src?

Jerome Carty - Follow jcarty on Twitter@jcarty | #webworks-dev / #BlackberryDev on irc.freenode.net | My Apps
Click "Accept as Solution" if post solved your original issue.. Give like/thumbs up if you feel post is helpful
Developer
Posts: 97
Registered: ‎10-06-2009
My Device: Not Specified

Re: Select images dynamically for Bitmap

i used the path some thing like res/img1/imagename.png and it works.Did you added that file to the project ??

Trusted Contributor
Posts: 105
Registered: ‎02-02-2011
My Device: Bold 9900
My Carrier: Airtel

Re: Select images dynamically for Bitmap

Am using JDE 4.6.0, 

I created "images" folder in main project folder and add two subfolders "img1" and "img2" 

 

 

Developer
Posts: 97
Registered: ‎10-06-2009
My Device: Not Specified

Re: Select images dynamically for Bitmap

instead of "images" folder create "img" or "res" folder.

Trusted Contributor
Posts: 105
Registered: ‎02-02-2011
My Device: Bold 9900
My Carrier: Airtel

Re: Select images dynamically for Bitmap

I create res folder and put img1 and img2 folder in it

then add images to project

 

Bitmap icon = Bitmap.getBitmapResource("res/img1/cotg.png");

 

is not working 

 

but

 

Bitmap icon = Bitmap.getBitmapResource("cotg.png");   is working fine

 

I want to select images with same name from different folders dynamically, Is it possible in blackberry

 

 

 

Developer
Posts: 97
Registered: ‎10-06-2009
My Device: Not Specified

Re: Select images dynamically for Bitmap

I don't know why it's not working for you.Just check the path once more (case sensitivity).you can put the same file in two diff folders and use it.There should not be any problem.

Trusted Contributor
Posts: 146
Registered: ‎03-22-2010
My Device: Not Specified

Re: Select images dynamically for Bitmap

try

 

Bitmap.getBitmapResource(

"img1/yourimage.png");