0

I am new to Java and are trying to display an image. I got code on the net but when trying it I get an error with the importing of " import javax.imageio.ImageIO;" The error message reads "javax.imageio.ImageIO" is either a misplace package name or a non-existing entity. I have seen this on many samples but it does not work with me. Is there any advice

mport java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
public class Showmap extends Panel
{
    BufferedImage img;
    public Showmap ()
    {
        try
        {
            image = ImageIO.read (new File ("KNP.jpg"));
        }


        /*
           catch (IOException e)
           {









               BufferedImage  image;
                 public ShowImage() {
                 try {
                 System.out.println("Enter image name\n");
                 BufferedReader bf=new BufferedReader(new
               InputStreamReader(System.in));
                String imageName=bf.readLine();
                 File input = new File(imageName);
                 image = ImageIO.read(input);
           }*/


        catch (IOException e)
        {
            System.out.println ("Error:" + e.getMessage ());
        }
    }


    public void paint (Graphics g)
    {
        g.drawImage (image, 0, 0, null);
    }



    static public void main (String args []) throws
        Exception
    {
        JFrame frame = new JFrame ("Display image");
        Panel panel = new Showmap ();
        frame.getContentPane ().add (panel);
        frame.setSize (500, 500);
        frame.setVisible (true);
    }
}

Thanks Ivan

user1492069
  • 11
  • 1
  • 4

2 Answers2

1

In your Project select:

  1. Right Click on "JRE System Libary"
  2. Select Properties
  3. On Execution Enviroment select "J2SE-1.5(jre8)" or later; you should use the latest version of jre8
andrewsi
  • 10,807
  • 132
  • 35
  • 51
0

I was programming with "Ready to Program" and tried many options with out success. When I copied the same code to "JCreator" and run it fro there it was working fine. Seems "import javax.imageio.ImageIO;" is not working with "Ready to Program".

user1492069
  • 11
  • 1
  • 4