Problem with setIconImage

Ok so i have this code in my source

Image icon = getImage("am.ico");

mainFrame.setIconImage(icon);

But when i try to compile i get this error

cannot find symbol method getImage(java.lang.String)

I tried putting import java.lang.String

But i still get the same error.

What do i need to do for this to work?

[380 byte] By [The_Undeada] at [2007-11-27 11:21:22]
# 1

Where is the getImage method? Apparently it is not in your class.

floundera at 2007-7-29 14:48:20 > top of Java-index,Java Essentials,New To Java...
# 2

Would trying something like:

ImageIcon icon = new ImageIcon("am.ico");

work?

petes1234a at 2007-7-29 14:48:20 > top of Java-index,Java Essentials,New To Java...
# 3

> Would trying something like:

> > ImageIcon icon = new ImageIcon("am.ico");

>

>

>

> work?

Well i now have this

ImageIcon icon = new ImageIcon("am.ico");

mainFrame.setIconImage(icon);

But now i get this

cannot find symbol method setIconImage(javax.swing.ImageIcon)

Oh and thanx for the replies

The_Undeada at 2007-7-29 14:48:20 > top of Java-index,Java Essentials,New To Java...
# 4

How about showing us more of your code. If it is large then only post the relevant sections. We can only guess from the snippets you are posting.

floundera at 2007-7-29 14:48:20 > top of Java-index,Java Essentials,New To Java...
# 5

What is mainFrame? Is mainFrame a JFrame?

You may need to show more of your code.

petes1234a at 2007-7-29 14:48:20 > top of Java-index,Java Essentials,New To Java...
# 6

The JFrame method setIconImage() requires an Image argument, not an Icon. (An ImageIcon is an Icon, it is not an Image).

Try using the ImageIO.read() to get a BufferedImage - it accepts both a File or a URL as an argument. Then use this BufferedImage as the argument to setIconImage().

pbrockway2a at 2007-7-29 14:48:20 > top of Java-index,Java Essentials,New To Java...
# 7

Thanx to all who posted but i fixed it with this

Image icon = Toolkit.getDefaultToolkit().getImage("am.png");

mainFrame.setIconImage(icon);

The_Undeada at 2007-7-29 14:48:20 > top of Java-index,Java Essentials,New To Java...
# 8

cool. good luck

petes1234a at 2007-7-29 14:48:20 > top of Java-index,Java Essentials,New To Java...