| Reply | « Previous Thread | Next Thread » |
|
I've been trying to load a png image.
but somehow my program only catches IOException which means it couldn't find it. I'm writing a program for Nokia 6310i using its emulator and Sun Forte 4. I've checked Tool -> Create Application Package and can see the image file there. but it doesn't appear when I run the emulator. this is my directory structure where test has three Java source file and res contains the image file project\test project\res please help. thanks |
|
Hello,
There are three possible pitfalls you might have fallen into: 1. You should refer to the image with an absolute path Reading image: public class ImageCanvas extends Canvas { Image picture; public ImageCanvas () { try { picture = Image.createImage("/thal.png"); } catch (IOException ioe) {} } Reading text file: InputStream is; byte[] baText = null; try { is = Class.forName("java.lang.Object").getResourceAsStream ("/myFile.txt"); // or is = this.getResourceAsStream("/myFile.txt"); } catch (ClassNotFoundException cnfe) {} // Read menu file into byte array try { is.read(baMenu); } catch (IOException ioe) {/* Some kind of Alert here if file not found*/} finally { try { is.close(); } catch (IOException ioe) { /* Close failed */ } } 2. Check that the file name is written exactly right in your program (lower case/ upper case characters) 3. Check that you have actually included the resource file in your jar file (double-click the jar file and check contents) Regards, Petteri / Forum Nokia |
|
Hi pbergius,
I had tried that code, but I had caught an error: teszt001.java [19:18] cannot resolve symbol symbol : method getResourceAsStream (java.lang.String) location: class teszt001 is = this.getResourceAsStream("/myFile.txt"); 1 error Errors compiling teszt001. Correctly, in my opinion: is = this.getClass().getResourceAsStream("/myFile.txt"); I'm using Forte for Java, Mobile Edition v.4.0. (WinXP HU) Regards, Attila WAP: http://java.moricznet.hu |
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|