You Are Here:

Community: Developer Discussion Boards

#1 Old how to load an image(.png) in Forte 4 - 2002-10-07, 06:11

Join Date: Mar 2003
Posts: 1
xtman1
Offline
Registered User
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
Reply With Quote

#2 Old RE: how to load an image(.png) in Forte 4 - 2002-10-07, 06:54

Join Date: Mar 2003
Posts: 419
Location: Irving, Texas, USA
pbergius
Offline
Regular Contributor
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
Reply With Quote

#3 Old RE: how to load an image(.png) in Forte 4 - 2002-10-10, 13:32

Join Date: Mar 2003
Posts: 20
morati
Offline
Registered User
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 With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Forum Jump

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia