| Reply | « Previous Thread | Next Thread » |
|
My code was loading an image from a resource like this: "Image blabla = Image.createImage(this.getClass().getResourceAsStream("blabla.png"));" just as the manual i got from Sun's says.
The interesting thing being, that Image.createImage() wants a string, but Class.getResourceAsStream() return InputStream, but the emulator with WTK2 liked it and it worked. When i ran the same code on the emulator of 7210, it gave me an error, that no such Image.createImage() exsists, which takes InputStream as an argument. I checked the docs given with the 7210 SDK and it didnt said that getResourceAsStream should be used in case of that function, but it still says that decoded image data is the argument. So what am i getting wrong? I tried to give just the images path as the argument for createImage, but i got NullPointerException. Maybe there is a way of getting the Resource to a String, that i dont know of? |
| ronaldvoneifeld |
| View Public Profile |
| Find all posts by ronaldvoneifeld |
|
Image blabla = Image.createImage("\blabla.png"); - It could be that you did not specify the root "\"
By the way Class.getResourceAsStream() returns an InputStream. This is used to load in data files |
|
I created the application package with Nokia Dev Suite and it found the picture and showed the right path for it and i used that path in the code. So this isnt the problem.
|
| ronaldvoneifeld |
| View Public Profile |
| Find all posts by ronaldvoneifeld |
|
That method definitely takes the path to the image in your jar.
Open up you jar (with WinZip, or WinRAR, etc.) and check to see under what path your SDK actually saved it. Also make sure that the name of the file is exactly the same (case is important - hello.PNG != hello.png). shmoove |
|
The .jar has the file and the file name is written correctly in the code.
|
| ronaldvoneifeld |
| View Public Profile |
| Find all posts by ronaldvoneifeld |
|
OK. So show us the code you sue to load the Image, and what is the path to the image in the jar.
shmoove |
|
www.hot.ee/ronn/jp/GameCanvas.java
Other files(AirBattlesMIDlet.java and GameThread.java) are in the same dir. The completed packages are MyMIDlet.jad and MyMIDlet.jar also in the same dir. |
| ronaldvoneifeld |
| View Public Profile |
| Find all posts by ronaldvoneifeld |
|
Dont know if this will help but I have all my graphical and data resources in the "res" directory and all source files in the "src" directory
|
|
I don't see anything wrong with the code loading the image (that paint() method is a little confusing though). As long as the jar has an image called test.png in the root path (not in any subfolder), it should load just fine. Are you getting the "Viga pildi laadimisel" message?
shmoove |
|
I hold my images also in "res" directory.
Yes, the exception gets thrown(the error message printed). |
| ronaldvoneifeld |
| View Public Profile |
| Find all posts by ronaldvoneifeld |
|
Have you tried loading a different image? Maybe the image is too large, in the incorrect format or simply a corrupted file?
|
|
This is sounding more and more like a path issue.
Quote:
Open up the jar with a zip utility and look at the path to that image. If it's not in the root directory of the jar (ie, it's in a res directory in the jar), then that's your problem. Either change the location of the file in the jar, or change the path in your code to include the directory it is in (ie, Image.createImage("/res/test.png");). If it is, it should be loading properly, so maybe it is a problem with the file itself like mrmop said. shmoove |
|
Since it worked on other emulators, i didnt think that image could be a problem, but i made a new image and it worked. Maybe my first image really was too big.
Thank you all for your help and sorry for wasting your time. |
| ronaldvoneifeld |
| View Public Profile |
| Find all posts by ronaldvoneifeld |
|
No problem and it wasnt a waste of time, we've discovered another emulator-device incompatibility :)
|
|
I just had this same problem.
The original .png I had was something I created in Photoshop. I then switched to a .png I found in an example app and it worked! ? what's the deal? Drew |
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|