Images in MIDP 1.0

Hi guys, im new to the forum and could really do with some help!
I’m writing a crossword game in MIDP 1.0 for my final year project and im having problems with my images.
The basic game is finished, it ‘builds’ fine in the emulator and works fine through the ‘run’ button.
However… when i build the package, the game does not work when i double click on the jad and i get the runtime error ‘images not found’
I dont understand this, the images are all held in the pngs are all held in the ‘res’ folder, but somehow are not linked to?
i load all my images vis the 'Image.createImage("/example.png") command.
I’m really confused, ive tried moving the images around the various folders but it makes no difference, any help would be greatly appreciated.
Cheers guys

Rich :slight_smile:

Hey,

Solved my own problem, very stupid mistake!!!

For future reference for those with similar problem,

("/example.PNG") NOT ("/example.png") its case sensitive!

Still now i have a nullPointerException, ho hum…

Rich

::slight_smile:

Glad you sorted your initial problem, do you have any screen shots of your application so far?

Hey Ribbot,

Cant send u any screenshots as of yet because the problem has resurfaced! maybe u can help?

I’m pretty sure that the case sensitivity is the problem so i changed all my src files so that the extensions were uppercase (ie. PNG not png) as this is how the images are saved in the res folder.

However, despite the changes in the source files, the jar still lists the images with lowercase extensions, hence leading to ‘images not found’ errors?

I’m puzzled, why are the changes in the src code not filtering through to the jar?

any thoughts much appreciated???

Cheers

Rich ???

You had it in the earlier code sample, but make sure you have a / in front of your file names. That one bit me once.

("/example.png")

You can also dump the contents of your jar to make sure it does have the file in it. You never know.

jar -tvf yourfile.jar

Wood

Maybe you need to recompile your class file or any other class files that use it… i know it sounds silly but depending on the development environment this may have an effect ???

Right,

Much appreciative of the help so far and have had a mini break through, by changing the error messages on the different image creations i’ve narrowed it down to the following piece of code.

Its a constructor that creates a list of numbered options and appends the same png as an icon to each element via a for loop:


public CrosswordList(){

      super("Clue Number:", List.IMPLICIT);

      for(int i=0; i<board.numberOfClues; i++){

            // initialise list and append image icons

            try{

                  append(clueList[i], Image.createImage ("/clueImage.png")); 
            
            } // end of try

            catch (java.io.IOException x) {
          
                  throw new RuntimeException ("Images not found");

             } // end of catch


      } // end of for loop

      // add commands to list

      addCommand(showClue);
      addCommand(backList);
      setCommandListener(this);

} // end of overidden constructor


Ive included the whole constructor for completeness but its this bit that causes the problem because commenting it out removes the error:


for(int i=0; i<board.numberOfClues; i++){

            // initialise list and append image icons

            try{

                  append(clueList[i], Image.createImage ("/clueImage.png")); 
            
            } // end of try

            catch (java.io.IOException x) {
          
                  throw new RuntimeException ("Images not found");

             } // end of catch


      } // end of for loop


Thanks for the help guys

Rich

Open up the jar (with any zip utility) and check that the file is there, and that it’s in the root directory (since that’s how you’ve coded it).

On a separate note, you are creating a new image for every item in the list. That’s very wasteful. I suggest you change it to:


 Image clueImage;
 try {
  clueImage = Image.createImage ("/clueImage.png");
 }
 catch (Exception e) {
  // instead of throwing an exception here
  // you should be displaying the data from this exception
  // to help you with the debugging, so I would create an 
  // Alert or something like that instead of throwing
  // a RuntimeException
 }
 for(int i=0; i<board.numberOfClues; i++){
  append(clueList[i], clueImage);     
 } // end of for loop
 

shmooove

Cheers for the advice shmooove,

When i looked back over the code i realised how wasteful it was so moved the image creation outside and for some reason that fixed the error!

Not complaining though!

Should be ready for porting OTA soon, will post the URL when ready.

Thanks again for everyones’ input.

Rich

;D

[quote]so moved the image creation outside and for some reason that fixed the error!
[/quote]
Smells like “out of memory” from here.

shmoove