Image.createImage definitely not working...

I have some incredibly simple code below because I was trying to see what the heck was wrong with createImage...

public class Viewer extends MIDlet

{

protected void startApp() throws MIDletStateChangeException

{

Image anImage;

try {

anImage = Image.createImage("/011.png");

}

catch (IOException e) {

e.printStackTrace();

}

}

protected void pauseApp(){ }

protected void destroyApp(boolean arg0) throws MIDletStateChangeException { }

}

It gives me an error and it is kind of strange. 011.png DOES exist and was created using PSP. I tried it in a /res folder and in the root folder of the project. I've read the forums here, but nothing has helped me so far. Can anyone tell me what could be going on here?

[812 byte] By [limousinedriver] at [2007-9-30 20:35:31]
# 1
What's the error?
paulcw at 2007-7-7 1:24:56 > top of Java-index,Other Topics,Java Game Development...
# 2

According to the Java 1.5 API (http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Image.html), there's no such method in the Image class. In fact, Image is an interface, so you couldn't invoke methods statically even if such a method DID exist. Therefore, your compiler error (if it indeed is a compile error) is caused by calling an undefined method.

However, given that I don't know what the MIDlet class is (because it's not in the Java 1.5 API at all), you may be using some package I've never heard of. In that case, check the API for that package.

SheepNine at 2007-7-7 1:24:56 > top of Java-index,Other Topics,Java Game Development...
# 3
A listing of the different ways to create a new image are listed here: http://weblogs.java.net/blog/chet/archive/2004/08/toolkitbuffered.html
jboeing at 2007-7-7 1:24:56 > top of Java-index,Other Topics,Java Game Development...
# 4
Hes using J2ME CLDC MIDP, not J2SE.
Abuse at 2007-7-7 1:24:56 > top of Java-index,Other Topics,Java Game Development...
# 5

I've got the same problem but with Sun ONE Studio 4 ME. I've already checked all the MIDP/CLDC Tutorials I could find, and they all give close to this example. (Image img = CreateImage("/img.png")) All of them finaly end up with img = (null). Me too have tried the \res folder, I suppose I am making a very dumb mistake, but I'm stuck with no ideas. Can't one of You gurus write a simple example? Pls!!

Happy_user at 2007-7-7 1:24:56 > top of Java-index,Other Topics,Java Game Development...
# 6
Post the complete error code & stack trace.also an ls/dir of the /res folder would be nice.Rember that jars are Caps sensative.
mlk at 2007-7-7 1:24:56 > top of Java-index,Other Topics,Java Game Development...
# 7

> anImage = Image.createImage("/011.png");

> 011.png DOES exist and was created using PSP.

> I tried it in a /res folder and in the root folder of

> the project.

Have you tried putting 011.png in the root directory of your hard drive? That's what a single / in front of a filename usually means. Try taking that slash out, or replacing it with "res/" if you want the images in a "res" folder. (Assuming that "res" folder is a subdirectory of your Java project directory.)

I too am unfamiliar with the Image.createImage method. What I always use in my applets is something like this:

Image image = getImage(getCodeBase(),"filename.jpg");

I think getImage is a method of the Applet class, but I don't remember.

StevenRoy at 2007-7-7 1:24:56 > top of Java-index,Other Topics,Java Game Development...
# 8
StevenRoy , this is a J2ME question, NOT a J2SE.
mlk at 2007-7-7 1:24:56 > top of Java-index,Other Topics,Java Game Development...
# 9
They must be more different than I thought. Never mind, then.
StevenRoy at 2007-7-7 1:24:56 > top of Java-index,Other Topics,Java Game Development...
# 10
Aye they are, only the very basics (a subset of java.lang, io and util) are common to them both.
mlk at 2007-7-7 1:24:56 > top of Java-index,Other Topics,Java Game Development...
# 11
http://www.j2mepolish.org/documentation.htmlThis site may help u out in the above case I am also encountering the same problem
abhijeet_mumbai at 2007-7-7 1:24:56 > top of Java-index,Other Topics,Java Game Development...
# 12
Feb 12, 2005 5:52 PMJan 1, 2006 1:55 PMPlz check the date b4 reposting
Futurisdom_Developer at 2007-7-7 1:24:56 > top of Java-index,Other Topics,Java Game Development...
# 13

I know that is an OLD post, but is still first on Google ranking today, so will be good to have a solution also at this time :)

I found this problem when i was working with an IDE (JBuilder) and the problem was that i needed to BUILD to classes target also the content of the RES folder (all resurces must be added to project, and set to COPY)

That will solve the problem in my case.

Bye

P鄐cal

Pascaly at 2007-7-7 1:24:56 > top of Java-index,Other Topics,Java Game Development...