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
New Developer
Posts: 3
Registered: ‎02-09-2009
My Device: Storm 9500
Accepted Solution

Bitmap.getBitmapResource(...) not finding my file?!

[ Edited ]

Hi all, I'm a 1st year student at the University of Warwick (UK) and I'm trying to write a little application for the Blackberry Storm but I can't get my code to work right...


Bitmap image = Bitmap.getBitmapResource("c.gif" ) ;

BitmapField bField = new BitmapField(image, BitmapField.FOCUSABLE ) ;

add(bField ) ;

 

if(image == null) {add(new RichTextField("null!" ) ) ; }


^^ the snippet above is what I've written, as far as I can see it's all fine, and the file c.gif is in the same directory as the .java source code when I try to build the project (in the RIM JDE)

 

When I run my application in the simulator, instead of the image being displayed, I just get "null!" printed...

 

I'm sure I'm just doing something stupid/obvious but I've tried moving the .gif around to different folders but I just can't get it to work

 

Thanks for reading this,

 

Harri

Message Edited by HarriBanjo on 02-09-2009 05:03 PM
Message Edited by HarriBanjo on 02-09-2009 05:05 PM
Developer
Posts: 19,612
Registered: ‎07-14-2008
My Device: Not Specified

Re: Bitmap.getBitmapResource(...) not finding my file?!

Have you added the file to the project?
New Developer
Posts: 3
Registered: ‎02-09-2009
My Device: Storm 9500

Re: Bitmap.getBitmapResource(...) not finding my file?!

Thanks for the fast reply, I had a added a file to the project but looking at it again when you asked I realised I hadn't added the right one (I'd added the .png rather than the .gif) so obviously when it came to building it wasn't finding it.

 

I knew it would be something obvious, thanks again, I'll probably end up posting again on here for this app as it's my first app for a BB device.

 

Thanks,

 

Harri

Developer
Posts: 19,612
Registered: ‎07-14-2008
My Device: Not Specified

Re: Bitmap.getBitmapResource(...) not finding my file?!

Feel free to post again, but as this question is solved, can I suggest you can mark it as such, to save someone else looking to answer your question.  Start a new post for your next question. 

 

Hope you are enjoying Warwick, I think the University is a nice place, though quite some distance from Warwick itself (which I also like)!

 

 

New Developer
Posts: 31
Registered: ‎07-06-2009
My Device: Not Specified

Re: Bitmap.getBitmapResource(...) not finding my file?!

i am having the same problem. I'm not quite sure how to add it to the project though. PLEASE HELP ME!

 

CustomMapField mapField = new CustomMapField();
...
mapField.mIcon = Bitmap.getBitmapResource("image.png");
...
class CustomMapField extends MapField { 
    Bitmap mIcon; 
...

 

its the Bitmap.getBitapResource(...);

 

gives me a null pointer excpetion :smileysad:

 

how do i do his?

 

many thanks

Contributor
Posts: 24
Registered: ‎07-08-2010
My Device: Blackberry 9000

Re: Bitmap.getBitmapResource(...) not finding my file?!

you need to add the png to the project (under src). let me know if this helps.

Contributor
Posts: 24
Registered: ‎07-08-2010
My Device: Blackberry 9000

Re: Bitmap.getBitmapResource(...) not finding my file?!

to add the file to the project, right click on the project file then import......hope this helps.

Visitor
Posts: 1
Registered: ‎09-12-2010
My Device: Not Specified

Re: Bitmap.getBitmapResource(...) not finding my file?!

i have the same problem.

 

Background bg = BackgroundFactory.createBitmapBackground( Bitmap.getBitmapResource( "image.png" ) );

 

btnFavoritas.setBackground( bg );

 

when i run the application, it shows me: "Uncaught exception: Bitmap invalid (null)"

 

i already verified that the name is correct, added the image by coping it, and by import. But none of this solved my problem...

Trusted Contributor
Posts: 138
Registered: ‎07-11-2010
My Device: Bold 9700

Re: Bitmap.getBitmapResource(...) not finding my file?!

 


dfpg wrote:

i have the same problem.

 

Background bg = BackgroundFactory.createBitmapBackground( Bitmap.getBitmapResource( "image.png" ) );

 

btnFavoritas.setBackground( bg );

 

when i run the application, it shows me: "Uncaught exception: Bitmap invalid (null)"

 

i already verified that the name is correct, added the image by coping it, and by import. But none of this solved my problem...


is it in your "res" folder? if not, make sure it's there.