๐ŸŽ‰ Celebrating 25 Years of GameDev.net! ๐ŸŽ‰

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Java - error: cannot find symbol

Started by
2 comments, last by macmanmatty 4ย years, 5ย months ago

I newly started programming java and am currently trying to figure out how to draw images. I get an error that tells me I am doing something wrong even though I am only doing what I learned on the oracle tutorials.

My error appears when I try to compile it with "cmd.exe". The error in detail is like this:

Pictures.java:18: error: cannot find symbol
                } catch (IOExeption e) {
                         ^
  symbol:   class IOExeption
  location: class Pictures
Pictures.java:27: error: cannot find symbol
                g.drawImage(img, 50, 50, null);
                            ^
  symbol:   variable img
  location: class Pictures
2 errors

And this is my java code:


import javax.imageio.*;
import java.io.*;
import java.awt.image.*;
import javax.swing.*;
import java.awt.*;

public class Pictures {
	
	static JFrame Frame = new JFrame("Pictures");
	
	public static void main(String[] args) {
		
		BufferedImage img = null;
		
		try {
			img = ImageIO.read(new File("Blacksquare.jpg"));
		} catch (IOExeption e) {
		}
		
		Frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		Frame.setSize(400, 400);
		Frame.setVisible(true);
	}
	
	public void paint(Graphics g) {
		g.drawImage(img, 50, 50, null);
	}
}
Advertisement

IOExeption is IOException, missing a โ€˜cโ€™. ?

Make sure to use an IDE with syntax highlighting. Many have addons for that.

๐Ÿ™‚๐Ÿ™‚๐Ÿ™‚๐Ÿ™‚๐Ÿ™‚<โ†The tone posse, ready for action.

your variable img is out of scope img needs to be a field if you want access it from other methods.

This topic is closed to new replies.

Advertisement