Jump to content
  • Advertisement
Sign in to follow this  
msiren

[J2ME] Loading resources with getResourceAsStream doesnt work

This topic is 4834 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello. I have this little problem when trying to load a file with getResourceAsStream within my j2me application. The method that is used for loading the files content is static so that might be one reason why loading resources doesn't work. I get IOException with no message when I am attempting to get resource as input stream. And I am 100% sure the file which I'm trying to load is in side the jar. Heres a little code to demonstrate:
class MyCanvas extends Canvas {
  MyCanvas canvas; // Initialized in construtor
....
  public static byte [] loadMyResource(String file)
  {
    try {
      InputStream is = canvas.getClass().getResourceAsStream("/" + file);
....
That is pretty much the piece of code I'm using, but I get exception and it doesnt go further that to canvas.getResourceAsStream(..). I've also tried following options: midlet.getClass().getResourceAsStream(..) Display.getDisplay(midlet).getCurrent.getClass().getResourceAsStream(..) ((MyCanvas)Display.....same as above....) None of these options work. And yes I am sure that the "/" + file produces the correct file name. I'm running out of options here... I'm just wondering what am I doing wrong or is there something wrong with resource loading in Sony Ericsson k500i which I'm using.

Share this post


Link to post
Share on other sites
Advertisement
In the sample code you posted "canvas" would need to be a static variable. And remember that filenames on the phone will be case-sensitive.

shmoove

Share this post


Link to post
Share on other sites
Thanks for the reply, but I already found the problem and it wasnt the getResourceAsStream, but reading from the file. Just used InputStream.skip() for skipping and everything worked. I knew this was going to happen that I post a question in the forum and found the solution for it before any replies =)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!