Could any one explain the path I need to use with Image.createImage("/test.png");
Where do I put the image on the computer for use with the emulator and where do I store it on the phone?
Could any one explain the path I need to use with Image.createImage("/test.png");
Where do I put the image on the computer for use with the emulator and where do I store it on the phone?
You put it in the JAR file. The JAR file is basically a ZIP file. Check your IDE's documentation for how to add resource files to the JAR.
Graham.
Question:
what IDE are you using?
Netbeans,
Eclipse
?
:Ruben
Eclipse, I must be real thick not found it in the doucmenatation yet!
If your project got created with a "res" folder, then put them there.
Are you using the Eclipse MTJ (Mobile Tools for Java)?
Graham.
I have copied the image into the res directory do I need to do anything else?
When I use:
Image Logo = Image.createImage("/test.png");
//ImageItem(label,Image,layout,alternative text)
ImageItem imageitem = new ImageItem("ImageItem Example", Logo, ImageItem.LAYOUT_CENTER,"");
StartScreen.append(imageitem);
I get the message:
Exception occurred: java.io.IOException: Cannot read /test.png
The code looks correct... assuming the file is in the right place!
Points to note:
1. You are right to put the leading "/". Filenames must start with a "/".
2. The name must match exactly. Strictly, implementations are case sensitive, so "/test.png" will not match "/Test.png". However, some implementations are insensitive, which results in code that works on some devices, but breaks on others. Do as you have done, and keep all resource file names all lower case. (Not source file names, they should follow the convention for class names.)
I suggest you build a JAR, and look inside it. You can use the command-line JAR tool (from the JDK) for this.
Or, open it with something like WinZIP (JAR files are just ZIP files).Code:jar tvf myapplication.jar
Check that "test.png" is in there, and check what path it's in. It could be missing, or it could be "/res/test.png", for example.
Graham.
No the image file s not in the jar manifest. What should I add in?
Is there no way of telling the eclipse IDE to add it in atuoamtically?
It needs to be in the JAR, not the MANIFEST. Is it in the JAR?
Yes, the IDE should include resource files for you. When you created the project, did it create a "res" folder for you? Or did you create the "res" folder?
Are you using eclipseME or the Eclipse MTJ?
Graham.
The res folder was created automatically for me. I have copied the file test.png into that folder. I am using eclipseME.
Thanks by the way for all your time on this
Hmmm... I'm at something of a loss.
I'm not a regular eclipseME user. You might want to try running through this tutorial, just to check that it works and you don't have any problems with your set-up. Go straight to section 4 (start a new project). It should only take you about 10 minutes. Maybe you'll spot some step that you missed, or some option that you didn't pick?
Graham.