You Are Here:

Community: Developer Discussion Boards

Reply « Previous Thread | Next Thread »

#1 Old createImage on 7210 - 2004-01-04, 22:07

Join Date: Jan 2004
Posts: 9
ronaldvoneifeld
Offline
Registered User
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?
Reply With Quote

#2 Old 2004-01-04, 23:00

Join Date: Mar 2003
Posts: 49
Location: United Kingdom
mrmop
Offline
24/7
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
Reply With Quote

#3 Old 2004-01-05, 16:49

Join Date: Jan 2004
Posts: 9
ronaldvoneifeld
Offline
Registered User
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.
Reply With Quote

#4 Old 2004-01-05, 18:08

Join Date: Mar 2003
Posts: 2,280
Location: Israel
shmoove
Offline
Forum Nokia Champion
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
Reply With Quote

#5 Old 2004-01-05, 19:06

Join Date: Jan 2004
Posts: 9
ronaldvoneifeld
Offline
Registered User
The .jar has the file and the file name is written correctly in the code.
Reply With Quote

#6 Old 2004-01-05, 19:48

Join Date: Mar 2003
Posts: 2,280
Location: Israel
shmoove
Offline
Forum Nokia Champion
OK. So show us the code you sue to load the Image, and what is the path to the image in the jar.

shmoove
Reply With Quote

#7 Old 2004-01-05, 19:59

Join Date: Jan 2004
Posts: 9
ronaldvoneifeld
Offline
Registered User
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.
Reply With Quote

#8 Old 2004-01-05, 20:07

Join Date: Mar 2003
Posts: 49
Location: United Kingdom
mrmop
Offline
24/7
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
Reply With Quote

#9 Old 2004-01-05, 20:20

Join Date: Mar 2003
Posts: 2,280
Location: Israel
shmoove
Offline
Forum Nokia Champion
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
Reply With Quote

#10 Old 2004-01-05, 21:44

Join Date: Jan 2004
Posts: 9
ronaldvoneifeld
Offline
Registered User
I hold my images also in "res" directory.
Yes, the exception gets thrown(the error message printed).
Reply With Quote

#11 Old 2004-01-05, 22:06

Join Date: Mar 2003
Posts: 49
Location: United Kingdom
mrmop
Offline
24/7
Have you tried loading a different image? Maybe the image is too large, in the incorrect format or simply a corrupted file?
Reply With Quote

#12 Old 2004-01-06, 00:13

Join Date: Mar 2003
Posts: 2,280
Location: Israel
shmoove
Offline
Forum Nokia Champion
This is sounding more and more like a path issue.
Quote:
I hold my images also in "res" directory.
Is that res folder in the jar or in your development environment?
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
Reply With Quote

#13 Old 2004-01-06, 14:36

Join Date: Jan 2004
Posts: 9
ronaldvoneifeld
Offline
Registered User
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.
Reply With Quote

#14 Old 2004-01-06, 15:00

Join Date: Mar 2003
Posts: 49
Location: United Kingdom
mrmop
Offline
24/7
No problem and it wasnt a waste of time, we've discovered another emulator-device incompatibility :)
Reply With Quote

#15 Old 2004-01-16, 01:47

Join Date: Jan 2004
Posts: 4
drewlane
Offline
Registered User
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 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 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomE2fforumE2fshowthreadE2ephpE3ftE3d134434X qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE44iscussionQ qdcZtypeQUqfntypeZE44iscussionContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZentertainmentQ qfnZtopicQUqfnTopicZj2meQ qfnZtopicQUqfnTopicZjavaQ qfnZtopicQUqfnTopicZmediaQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE44iscussionQ qfnZtypeQUqfntypeZE44iscussionContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE44iscussionQ qrdfZtypeQUqfntypeZE44iscussionContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ