# createImage(String) not working?

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

## Recommended Posts

Ok, so I got this phone for my birthday today. Nothing fancy (Nokia 5140i), but it's better than my 7 year old one... Anyhow, I figured I'd try to program some games to it using J2ME. Naturally, I want to be able to load .PNG:s as a graphical resource. This does not appear to work however, neither in an emulator nor the phone, despite everything indicating it would work. As far as I know the phone is CLDC/MIDP2.0/JTWI compatible. Is there some mysterious missing fact I've missed here? It's hilarious because I've worked on a simple side scroller the entire day under the assumption it would be able to render images... Effectively screwing up my entire plan if it can't. Any advice would be welcome. Ask me what code to show and I'll show it; anything to help solve the problem.... To start off, why wouldn't this work:
//this code is taken from within my Game class:
private Image[] images = new Image[1]; //declared as an array so I can extend it for all graphics I need

//now, this below method throws the IOException no matter what
//yes, I do have player.png as a correct PNG in the correct res dir
//also, I've tried with example PNGs that came with the WTK, and they also throw same exception
{
try
{
images[0] = Image.createImage("player.png");
}
catch(IOException ie)
{
owner.destroyApp(false);
owner.notifyDestroyed();
}
}



##### Share on other sites
Are you sure that image is in the right resource dir? REALLY sure? Everything else looks good.

##### Share on other sites
I use the KToolbar in the WTK to handle my compilation, so this far I've been assuming it manages to handle my compilation. You're right about that it should not be taken for granted though, because I'm quite sure I went through all other possibilities of screwing this up. It sets up the following paths for this (and other) projects:

apps\x\bin
apps\x\classes
apps\x\lib
apps\x\res
apps\x\src
(where x is the project name)

Now, it finds my .java files in the source directory (without any kind of sub directories here). All classes are in their appropiate directory, as well as the .jar. Also, my compiled .jar increases in size when I add .png files in the res directory so I'm for that reason quite sure they are in.

The really weird part is that the emulator that comes with the WTK isn't able to load its own graphics either in the "Games"-example that shows image loading. In that case however, it even seems to have accounted for that and has a backup consisting of primitive shapes. Obviously, my side scroller can't use that approach though as flying rectangles shooting ellipses make for quite boring play.

I hate this... Too weird to be true. Still it has to be a common problem considering neither the emulator nor the telephone manages to load .PNGs, both in the example games and in my game.

##### Share on other sites
Open the jar file and verify that the PNG is there and in the right directory. I'm sure most compressing software can open jars. If yours can't, try Filzip.

I've seen some mobile phones having trouble loading PNG files usually because of the pallete on those images. How many colors are you using? Try using 128 colors (no phones I've used ever had problems handling a 128 color PNG so I guess it's a safe number).

Are you using a generic device within the WTK emulator or are you using the Nokia recomended device to emulate your phone? Check your phone's page on Forum Nokia and get the recommended emulator from the Series 40 Platform 2.0 SDK.

##### Share on other sites
Quote:
 Original post by SneftelThe pathname for createImage needs to start with a slash.

That did it. Now, can anyone tell me why SDK examples weren't right then? Didn't they update them since some kind of change took place?

Blew: Yeah, I recalled now having downloaded the emulator. Didn't take notice during the time I did though because I was searching for the SDK by then. Going to use it from now on.

##### Share on other sites
It's required by the standard, but a lot of implementations--including, IIRC, certain versions of the WTK emulator--don't enforce it.

##### Share on other sites
Damn, I should have remembered that. Specially since I had the same problem some time ago. *g*

1. 1
Rutin
26
2. 2
3. 3
JoeJ
20
4. 4
5. 5

• 9
• 9
• 9
• 46
• 41
• ### Forum Statistics

• Total Topics
631750
• Total Posts
3002060
×