Skip to main content

Embedding files

3 replies [Last post]
asterfr
Offline
Joined: 2008-07-17
Points: 0

I'm developping a JME application using Eclipse and its plugin EclipseME. I would like to use one image from my own file system in my program. But I don't know how to do it. The image isn't push from my project to my emlator (I'm using sun wtk).

Bye

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
sfitzjava
Offline
Joined: 2003-06-15
Points: 0

Since JavaME doesn't have a "filesystem" (unless you are using the PIM jsr-75) the way to get access to file in your project is via a call like this:
.getClass().getResourceAsStream(filenameString);

For images you can simply use: Image.createImage(filenameString);

You package your resource into your jarfile by making a subdirectory in your project root path called "res". Then put your images in that directory. The WTK will take the contents of your src directory and the res directory and put them into your jarfile for deployment to the device. For the emulator you do not have to package the project, the emulator uses the resource directory.

In the EclipseME plugin, I believe you have to setup the project to recognize that the "res" directory is for your resources. Else you can simply put a res directory in your src directory and that should also do the trick.

hope that helps.
-Shawn

asterfr
Offline
Joined: 2008-07-17
Points: 0

It doesn't work, i've already put my images in /res but I'm unable to access them without having an IOException.

My res directory was already defined it EclipseME.

However thanks !

Fräntz

asterfr
Offline
Joined: 2008-07-17
Points: 0

l made it works : do not use "_" in your filenames !

Bye